process for uploading image to friends wall,
frist uploading image to user wall, and den in response getting image id and link,
unable to post image on friends wall,please suggest me if any fb configuration and fb permissions needed?
if (hasPublishPermission()) {
RequestBatch requestBatch = new RequestBatch();
for (GraphUser friend : selectedFriends) {
Bundle parameters = new Bundle();
Constants.showLog(TAG, String.valueOf(friend.getFirstName()));
parameters.putString("message", "Greetings!!");
parameters.putString("link", imagelink);
parameters.putString("picture", imagelink);
parameters.putString("target_id", friend.getId());
requestBatch.add(new Request(Session.getActiveSession(), friend.getId() + "/feed", parameters,
HttpMethod.POST));
Constants.showToast(this, "Posted picture on your friends wall");
}
requestBatch.addCallback(new Callback() {
#Override
public void onBatchCompleted(RequestBatch batch) {
Constants.showLog(TAG, "Posted to :" + batch.size());
}
});
Request.executeBatchAsync(requestBatch);
}
See the Feb 6th breaking changes here https://developers.facebook.com/roadmap/completed-changes/
Namely: "Removing ability to post to friends walls via Graph API".
You are no longer able to directly post to a friend's wall via Graph requests. You need to use the feed dialog.
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
I want to know how to send app request to all my facebook friends from android app. I tried in graph API. But, couldn't get it done.
https://graph.facebook.com/apprequests?ids=friend1,friend2&message='Hi'&method=post&access_token=ACCESS_TOKEN
I know this is a Duplicate question. But, couldn't find an answer yet.
I'm getting this error on the above API.
"All users in param ids must have accepted TOS."
I hope there will be a way to send app request to all friends from mobile on a click. Please share it.
The error message you receive ("All users in param ids must have accepted TOS") is because you are trying to send an app generated request to a user who is not connected to your app.
See the developer docs here.
Requests sent with the request dialog and app generated requests are different and you can't use app generated requests to invite users to your app.
Sending Facebook app requests are not available via the graph api. You can use the app requests java-script dialog to send the request though, you would just need to specify the user's id in the "to" property as detailed in the documentation.
Sample function:
<script>
FB.init({ appId: '**appId**', status: true, cookie: true, xfbml : true });
function sendRequest(to) {
FB.ui({method: 'apprequests', to: to, message: 'You should learn more about this awesome site.', data: 'tracking information for the user'});
return false;
}
</script>
Then just wire an onclick for each image to something like onclick="return sendRequest('**friendId**');"
Also you can call this function in javascript: It will give you all friends with photos. Also group of friends who are currently using same app. You can send request to any of them.
function sendRequestViaMultiFriendSelector() {
FB.ui({
method: 'apprequests',
message: "You should learn more about this awesome site."
});
}
See Facebook Friend Request - Error - 'All users in param ids must have accepted TOS'
Have you seen demo of "Hackbook" in the developer.facebook.com ?
You can refer HACKBOOK APP REQUEST FROM HERE.
You can achieve to post the app request to only one friend by below code.
Code:
Bundle params = new Bundle();
JSONObject attachment = new JSONObject();
JSONObject properties = new JSONObject();
JSONObject prop1 = new JSONObject();
JSONObject prop2 = new JSONObject();
JSONObject media = new JSONObject();
JSONStringer actions = null;
try {
attachment.put("name", "YOUR_APP");
attachment.put("href", "http://www.google.com/");
attachment.put("description", "ANY_TEXT");
media.put("type", "image");
media.put("src", "IMAGE_LINK");
media.put("href", "http://www.google.com/");
attachment.put("media", new JSONArray().put(media));
prop1.put("text", "www.google.com");
prop1.put("href", "http://www.google.com");
properties.put("Visit our website to download the app", prop1);
/* prop2.put("href", "http://www.google.com");
properties.put("iTunes Link ", prop2);*/
attachment.put("properties", properties);
Log.d("FACEBOOK", attachment.toString());
actions = new JSONStringer().object()
.key("name").value("APP_NAME")
.key("link").value("http://www.google.com/").endObject();
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println("ACTIONS STRING: "+actions.toString());
System.out.println("ATTACHMENT STRING: "+attachment.toString());
params.putString("actions", actions.toString());
params.putString("attachment", attachment.toString()); // Original
params.putString("to", "YOUR_FRIEND_FACEBOOK_ID");
Utility.mFacebook.dialog(getParent(), "stream.publish", params,new PostDialogListener());
public class PostDialogListener extends BaseDialogListener {
#Override
public void onComplete(Bundle values) {
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getApplicationContext(), ""+getResources().getString(R.string.facebook_response_msg_posted), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), ""+getResources().getString(R.string.facebook_response_msg_not_posted), Toast.LENGTH_SHORT).show();
}
}
}
Above code works perfect if you want to post the Apprequest only on One friend's wall. If you want to post on all then you have to make asynckTask which runs for all the friends post and post App request on all walls.
Update
Here is the link in PHP that have done same work to send request to all Facebook friends.
And [here it is clearly explained3 that it is blocked by Facebook to send a Friend Request to more then 15-20 friends.
Now, you have to only one option to do it is, use above code in AsyncTask to send Friend Request to all Friends One-by-One.
I want to send posts from Android to Facebook wall. Some initial code works but in my post occurs following problems:
If I set "link" in post then on top of post appears description a la
"JohnDoe published link from application SomeApp".
I want to have in top only standard user name a la "John Doe".
If I set picture in post then link to picture becomes link where user lands after clicking on post.
I want to show picture from eg. "mysite.com/picture.png" but after click on post I want to take user to "www.myadres.com".
I am trying to find solution basing on Graph API [as REST API is now deprecated].
Snippet of current code making above behaviour.
Bundle params = new Bundle();
params.putString("message", "test message");
params.putString("link", "http://www.google.no");
params.putString("caption", "app caption");
params.putString("description", "this app is about ...");
params.putString("picture", "http://www.facebookmobileweb.com/hackbook/img/facebook_icon_large.png");
params.putString("name", " just won 1M500");
Utility.mAsyncRunner.request("me/feed", params, "POST", new BaseRequestListener() {
#Override
public void onComplete(String response, Object state) {
System.out.println("response = " + response);
}
}, null);
Thank you in advance for help!
Best Regards
GT
To make post that looks like "normal user post "[and not like "sharing links"] post it with action "feed" and NOT "me/feed".
Finally:
Utility.mAsyncRunner.request("feed", params, "POST", new BaseRequestListener() {
#Override
public void onComplete(String response, Object state) {
System.out.println("response = " + response);
}
}, null);
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.
I'm new to Facebook API on Android, and basically, what I'm trying to do is creating custom wall post for an application I'm developing.
Like when you listen a Shazam a song and you can share the result with your friends.
I believe I've got to create a custom attachment. Here's my code for setting the attachment:
mPostButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Bundle myParams = new Bundle();
String attachment="{\"name\":\"Gran Turismo 5\"," +
"\"href\":\"http://www.unknown.com/?lang=fr\"," +
"\"caption\":\"Sony Computer Entertainment\",\"description\":" +
"\"Une vidéo proposée par Cedemo.\",\"media\":" +
"[{\"type\":\"image\",\"src\":" +
"\"http://www.unknown.com/prepicture//thumb_title/15/15061_1.jpg\"," +
"\"href\":\"http://www.unknown.com/?lang=fr\"}],\"properties\":" +
"{\"Autre lien\":{\"text\":\"Cedemo\",\"href\":\"http://www.unknown.com\"}}}";
myParams.putString("attachment", URLEncoder.encode(attachment);
mFacebook.dialog(Option.this, "stream.publish",myParams,
new SampleDialogListener());
And then, later on:
public class SampleDialogListener extends BaseDialogListener {
public void onComplete(Bundle values) {
final String postId = values.getString("post_id");
if (postId != null) {
Log.d("Facebook-Example", "Dialog Success! post_id=" + postId);
mAsyncRunner.request(postId,values, new WallPostRequestListener());
} else {
Log.d("Facebook-Example", "No wall post made");
}
}
}
I didn't wrote the attachment String, It's just a test taken from another question made in this forum. Anyway, when I call myAsync.request, my app shows an error message, how am I supposed to pass the attachment to my dialog?
Hope I've been clear enough.
Are you sure you need to set custom parameters? It sounds like you can just want to post a Facebook message directly to the wall: you can do this by simply handing in the message parameter as a string -- you only need all that JSON if you want to attach an image etc. And note on facebook's page it says using this api call won't post a status update that others can see on their feed, it will just appear on their own wall. If you just want to post a message with a link you should just be able to use your mAsyncRunner (once you have your valid Facebook session) using this:
String message = "Post this to my wall";
Bundle parameters = new Bundle();
parameters.putString("message", message);
mAsyncRunner.request("me/feed", parameters, "POST", new WallPostRequestListener());
Also may help if you posted the error/response code you're getting from Facebook.