facebook, customized post on wall from Graph API - android

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);

Related

Android: Facebook 3.0 Post on friends wall using the FQL request response (As of Apr23,2013)

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

Posting image to friends wall android 3.0

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.

fbShare in android

Can anybody suggest a good method for creating a facebook share implementation for my application.
I have created the test account and API key for the facebook developer site...
I need to implement in such a way that,when the fbshare button is clicked,a particular content(dynamic content) should be posted as a status link in the corresponding linked facebook account...
Apart from the fb developers,i need some other way of implementing it...
Suggestions expected...(possibly better results expected)
Hi use this method in your code in facebook handler class
public void postToFBWall(final String message, final String image){
Thread thread = new Thread(){
public void run(){
try{
String descripton = "This is the plain text copy next to the image. All work and no play makes Jack a dull boy.";
Bundle parameters = new Bundle();
parameters.putString("message", message);// message to be posted on facebook wall
parameters.putString("link", image);//link of image to be posted on facebook wall
parameters.putString("name", "My wish");// name of link
parameters.putString("description", descripton);// description of you post
String response1 = facebook.request("me/feed", parameters, "POST");
Log.v("facebook response", response1);
}catch (Exception e) {
}
}
};thread.start();
}
Try this one
https://developers.facebook.com/docs/mobile/android/hackbook/
it may helps you.

send an invitation to facebook friends to join my website

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.

Creating a custom Wall Post with Facebook API on Android

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.

Categories

Resources