I have build an android application in which I've integrated faceboook using the facebook-sdk package.I've also succeded to retrieve in my application the name of all my facebook friends, their names and their id's.Further I want to send from my application an invitation to all facebook friends to join a website.Can u point me in the right direction cause I haven't found anything on the internet.Thank you
Try using the code below, if you follow the tutorials i gave you in your other question it will work no probs!
protected void postOfferToWall(String userID){
try {
if (isSession()) {
String response = mFacebook.request((userID == null) ? "me" : userID);
Bundle params = new Bundle();
params.putString("message", "message goes here");
params.putString("link", "http://mysite.com");
params.putString("caption", "Click the link");
params.putString("description", "description of link");
params.putString("name", "name of link");
params.putString("picture", "http://url.to.my.picture/pic.jpg");
response = mFacebook.request(((userID == null) ? "me" : userID) + "/feed", params, "POST");
Log.d("Tests",response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} else {
// no logged in, so relogin
Log.d(TAG, "sessionNOTValid, relogin");
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
}catch(Exception e){
e.printStackTrace();
}
}
For a quick reference using the Graph API to post to your friends wall, see Graph API - Facebook Developers. There is a subsection called Publishing, where they use curl to post to a friends wall. Of course you need to get the access tokens and permissions to do such activities but it is all explained here.
Related
My app generates custom listview of friends arrange by their birthday. So I have used SELECT name, uid, pic_square, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) order by birthday_date.
Now when the user click a friend(from the listview) it will prompt the user if s/he want to post to that friends wall. I know how to do it the old way, but I'm getting confuse because of How to send a post to Facebook friend's wall android SDK 3.0 .
In that question:
The Facebook SDK for Android provides a method to let you publish
stories from your app to a user's timeline. You can also use this
method to post a status update on your user's behalf. This method uses
the Graph API, and is an alternative to using the Feed Dialog
http://developers.facebook.com/docs/howtos/androidsdk/3.0/publish-to-feed/
also:
never use Graph-API for posting on friend's wall. because it is disabled after 6, Feb 2013. FB recommend u to use Feed Dialog for posting on friend's or your own wall. this is the link for how to use Feed Dialog : http://developers.facebook.com/docs/howtos/androidsdk/3.0/feed-dialog
I have seen both links, but both only show how to post on your own wall. Can anyone give me
a good latest example or at least, point me to the right direction on how to post to your friends wall using the FQL request response via Facebook Android SDK 3.x (As of the moment the version is 3.0.2b)?
I have found the solution. You only need to add the "to" and "from" parameters. Below is my sample:
For wall posting to a single friend:
private void publishFeedDialog(String friend_uid) {
Session session = Session.getActiveSession();
if (!hasPublishPermission()) {
// We don't have the permission to post yet.
session.requestNewPublishPermissions(new Session.NewPermissionsRequest(this, WRITE_PERMISSION));
}
if (user != null && friend_uid != null && hasPublishPermission()) {
final Activity activity = this;
Bundle params = new Bundle();
//This is what you need to post to a friend's wall
params.putString("from", "" + user.getId());
params.putString("to", friend_uid);
//up to this
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(), params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(activity,
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(activity,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(activity,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(activity,
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
}).build();
feedDialog.show();
}
}
For wall posting to many friends:
RequestsDialogBuilder instead of FeedDialogBuilder because the second one only allows multiple ids on the parameter "to", while the first one can receive many (not sure about the limit though, but I think is about 50)
credits to: gian1200
Possible duplicate... I think you should check the Demo FB provided
Facebook - Post to wall from Android application
UPDATED:
Well there is this.
http://developers.facebook.com/docs/howtos/androidsdk/3.0/publish-to-feed/
Facebook actually recommends using the Feed. Check it out
Im having alot of trouble trying to post to a friends wall using the Facebook api in Android. This is what I have at the moment:
if (facebook.isSessionValid()) {
String response = facebook.request((userID == null) ? "me" : userID);
Bundle params = new Bundle();
params.putString("message", "put message here");
params.putString("link", "http://mylink.com");
params.putString("caption", "{*actor*} just posted this!");
params.putString("description", "description of my link. Click the link to find out more.");
params.putString("name", "Name of this link!");
params.putString("picture", "http://mysite.com/picture.jpg");
response = facebook.request(((userID == null) ? "me" : userID) + "/feed", params, "POST");
Log.d("Tests",response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} else {
// no logged in, so relogin
Log.d("1234567890", "sessionNOTValid, relogin");
}
}catch(Exception e){
e.printStackTrace();
}
But this returns with this error:
12-11 21:34:06.604: D/FACEBOOK RESPONSE(14954): {"error":{"message":"(#200) Feed story publishing to other users is disabled for this application","type":"OAuthException","code":200}}
You probably created this Facebook application recently, which means the February 2013 breaking changes are enabled.
February's Breaking Changes include:
Removing ability to post to friends walls via Graph API
We will remove the ability to post to a user's friends' walls via the Graph API. Specifically, posts against [user_id]/feed where [user_id] is different from the session user, or stream.publish calls where the target_id user is different from the session user, will fail. If you want to allow people to post to their friends' timelines, invoke the feed dialog. Stories that include friends via user mentions tagging or action tagging will show up on the friend’s timeline (assuming the friend approves the tag). For more info, see this blog post.
We are disabling this feature starting in February, if you wish to enable it (only temporarily until February), go to your app dashboard > Settings > Advanced > Disable "February 2013 Breaking Changes"
I highly recommend against doing so, however, since starting February this functionality will cause your app to throw the same error again.
I have the solution that might help you, I am using this for my code and its working fine..
private void publishFeedDialog(String friend_uid) {
try{
Session mCurrentSession = Session.getActiveSession();
SessionTracker mSessionTracker = new SessionTracker(
getBaseContext(), new StatusCallback() {
public void call(Session session, SessionState state,
Exception exception) {
}
}, null, false);
String applicationId = Utility
.getMetadataApplicationId(getBaseContext());
mCurrentSession = mSessionTracker.getSession();
if (mCurrentSession == null
|| mCurrentSession.getState().isClosed()) {
mSessionTracker.setSession(null);
Session session = new Session.Builder(getBaseContext())
.setApplicationId(applicationId).build();
Session.setActiveSession(session);
mCurrentSession = session;
}
if (!mCurrentSession.isOpened()) {
Session.OpenRequest openRequest = null;
openRequest = new Session.OpenRequest(
NewFriendList.this);
if (openRequest != null) {
openRequest
.setDefaultAudience(SessionDefaultAudience.FRIENDS);
openRequest.setPermissions(Arrays.asList("email", "publish_actions"));
openRequest
.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
mCurrentSession.openForPublish(openRequest);
}
}
if (regobj != null && friend_uid != null ) {
final Activity activity = this;
Bundle params = new Bundle();
//This is what you need to post to a friend's wall
params.putString("from", "" + regobj.MyFBID);
params.putString("to", friend_uid);
//up to this
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this, mCurrentSession, params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(activity,
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(activity,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(activity,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(activity,
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
}).build();
feedDialog.show();
}
}catch(Exception e)
{
Log.d("Error", ""+e.toString());
}
}
This code will work for only one user, if you want to send it to multiple user then you can use RequestsDialogBuilder instead of WebDialog.
In my application user can share information with different apps using:
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Link from my APP");
shareIntent.putExtra(Intent.EXTRA_TEXT, "http://aaa.com/");
startActivity(Intent.createChooser(shareIntent,"Share via:"));
It works fine./gmail,sms,google+..../
The only problematic app is Facebook. It starts dialog, but there is no info in fields.
Tried different TAGs, bout nothing :(
The only result is: If I put URL as EXTRA_TEXT - it not shown as text, but Facebook dialog read tags from URL and place them on dialog frame.
Any ideas to fill data in dialog.
Already have code to share wia sdk with or without dialog but this is not good for some reasons.
You need to integrate facebook sdk
Go through the following link it shows how to integrate facebook sdk
[http://developers.facebook.com/docs/mobile/android/sso/][1]
and u need to put some code in your java file as follows
try {
String response = facebook.request("me");
Bundle parameters = new Bundle();
parameters.putString("message", " your link");
parameters.putString("description", "");
response = facebook.request("me/feed", parameters,
"POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} catch(Exception e) {
e.printStackTrace();
}
All problems disappear after putting correct Android Key Hash.
Now share works correct.
I'm trying to create an android application which would allow the users to post messages on their facebook wall and also on their friends wall.
I've been through a few tutorials but in each of them is done barely the same thing:integrate facebook in application, the login authorization and posting a predifined message on the walll.
I'm using facebook sdk and I wonder is possible for the user to write directly to his wall in a dialog window???
What kind of authorization I need and if u could give me an example would be great.Thank u!
Take a look at this tutorial here and there is part 2 here. It will guide you though setting up the application to use facebook. Once you have all that setup you can use a function like this to post a msg to someones wall:
/**
* Post to a friends wall
* #param msg Message to post
* #param userId Id for friend to post to or null to post to users wall
*/
public void postToWall(String msg, String userID) {
try {
if (isSession()) {
String response = mFacebook.request((userID == null) ? "me" : userID);
Bundle parameters = new Bundle();
parameters.putString("message", msg);
response = mFacebook.request(((userID == null) ? "me" : userID) + "/feed", parameters, "POST");
Log.d(TAG,response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} else {
// no logged in, so relogin
Log.d(TAG, "sessionNOTValid, relogin");
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
} catch(Exception e) {
e.printStackTrace();
}
}
I had used a facebook app to post message on wall from https://github.com/facebook/facebook-android-sdk.
Here after user allows the app to use his/her profile, dialog feed comes with an editable area to publish or skip. I want a predefined message there but user will not be able to modify it. I am able to send the predifined message but its editable. How to make it uneditable.
Does any one knows how to do it??
You can just use a function to post directly to the users wall. Just make sure that it is clear to the user that the button posts directly, perhaps use a dialog to get them to confirm they want to post. Here is the code I use:
/**
* Post to a friends wall
* #param msg Message to post
* #param userId Id for friend to post to or null to post to users wall
*/
public void postToWall(String msg, String userID) {
Log.d("Tests", "Testing graph API wall post");
try {
if (isSession()) {
String response = mFacebook.request((userID == null) ? "me" : userID);
Bundle parameters = new Bundle();
parameters.putString("message", msg);
response = mFacebook.request(((userID == null) ? "me" : userID) + "/feed", parameters, "POST");
Log.d(TAG,response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} else {
// no logged in, so relogin
Log.d(TAG, "sessionNOTValid, relogin");
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
} catch(Exception e) {
e.printStackTrace();
}
}
The dialog contains a WebView that loads the actual content from a Facebook URL. So to modify the editable area, you would need to modify the DOM of this webpage. See this question for more information about doing that. It is unclear to me from the answers in that question if this is possible. If it is, you'll need to add the code to the FbDialog class in the Facebook Android SDK.