I am posting a photo to FB using the new FB Android SDK 3.0. I am now looking for a way to set some more parameters than just the image itself and a simple text. I tried tons of different parameters, but non of them seem to do something.
What i would like to do is to add a link, an icon and, if somehow possible, a custom link item next to the Like and Comment links.
Here is an example of the icon and the custom link item from twitter:
And this is the code that I am currently using:
byte[] data = get binary image data;
Bundle postParams = new Bundle();
postParams.putString("name", "Image text");
postParams.putByteArray("picture", data);
// All these parameters do nothing...
postParams.putString("icon", "http://www.myimage.com/image.png");
postParams.putString("message", "XXX");
postParams.putString("caption", "Build great social apps and get more installs.");
postParams.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
postParams.putString("link", "https://developers.facebook.com/android");
Request request = new Request(Session.getActiveSession(), "me/photos", postParams, HttpMethod.POST);
Response r = request.executeAndWait();
The post looks like this:
1. Adding the icon
You can manage icons from your app's dashboard: https://developers.facebook.com/apps/APP_ID/appdetails
2. Adding an action link
What you can a "custom link" is in fact an "action".
The "action" you've seen on the Twitter's post has been done using the actions array from the Post table:
A list of available actions on the post (including commenting, liking,
and an optional app-specified action)
So, your only choice if you really want to add this action near Like ยท Comment is to create a Post into the Feed and not a Photo.
Here is an a priori working code:
postParams.putString("message", "XXX");
postParams.putString("caption", "developers.facebook.com");
postParams.putString("description", "A tool to help you learn and browse the Facebook Graph API.");
postParams.putString("actions", "[{
'name':'Test a simple Graph API call!',
'link':'https://developers.facebook.com/tools/explorer?method=GET&path=me'
/* ^ This link must direct to the application's connect or canvas URL.
You'll get an error otherwise. */
}]"
);
postParams.putString("type", "photo");
postParams.putString("link", "https://developers.facebook.com/tools/explorer/");
postParams.putString("picture", "http://blog.programmableweb.com/wp-content/ishot-44.png");
Request request = new Request(Session.getActiveSession(), "me/feed", postParams, HttpMethod.POST);
3. Test in the Graph API Explorer
4. Timeline preview
Related
I want to be able to seamlessly publish to a users Facebook feed from the background in my Android application. The user is fully aware of the content they are publishing, but the post will be made after a relatively long upload process, so the user should not be made to wait. I am using the Android Facebook SDK v4.1.2.
I see that I need to request the "publish_actions" permission from the user beforehand:
https://developers.facebook.com/docs/facebook-login/permissions/v2.3#reference-publish_actions
I can use the LoginManager to get the access token:
https://developers.facebook.com/docs/facebook-login/android/v2.3#access_profile
I am then not sure how to share a link to the users feed without using the ShareDialog:
https://developers.facebook.com/docs/sharing/android
This SO question suggests using the Request object for v3.x, which is equivalent to the GraphRequest object for v4.x:
https://developers.facebook.com/docs/reference/android/current/class/GraphRequest/
but I am not sure how to build the correct GraphRequest. I assume I need to publish a message to "/me/feed":
https://developers.facebook.com/docs/graph-api/reference/v2.3/user/feed
Can anyone tell me how to do this?
In writing the question I found my own solution from trawling the docs and examples. I need to publish a message to "/me/feed":
https://developers.facebook.com/docs/graph-api/reference/v2.3/user/feed
Bundle params = new Bundle();
params.putString("link", link);
GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(),
"/me/feed", params, HttpMethod.POST,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
}
});
request.executeAndWait();
After obtaining the "publish_actions" permission.
You should use the ShareApi class if you don't want to build the params bundle yourself.
Build a ShareLinkContent as you normally would:
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://your.url.com"))
.build();
Then call ShareApi:
ShareApi.share(content, new FacebookCallback<Sharer.Result>() {...});
I'm using Facebook's latest SDK for Android.
Is it possible to post a status with BOTH place AND picture?
My bundle looks like this:
Bundle postParams = new Bundle();
postParams.putString("message", "Hi there!!");
postParams.putString("picture", "http://www.peleozen.net/pics/2_bus_face_logo.jpg");
postParams.putString("place", "204519339582365");
When I make the request, it results in a status with only the picture.
Making the request without a picture results in a checkin
So...is it possible to do both?
You can post to the /me/photos endpoint, so in a sense you're posting a photo, adding a location to it and the caption is the message. So as an example, if using the latest SDK, you could take a look at the HelloFacebookSample and make the following changes to the postPhoto method to try this out:
....
Bundle params = request.getParameters();
params.putString("message", "Hi there!!");
params.putString("place", "166793820034304");
request.setParameters(params);
Request.executeBatchAsync(request);
....
For reference, see: https://developers.facebook.com/docs/reference/api/user/#photos
hey I'm using this code technique to post on my fb wall
// parameters.putString("description", "Muslim Baby Names");
parameters.putString("picture","http://img208.imageshack.us/img208/4834/pic1qu.png");
it does make a post but picture odes not get posted.
Kindly tell me how should I do it
Check out our example app that uses the Android SDK, Hackbook. Here is the relevant code that uploads a photo to a user's wall from a remote URL.
For your example, this is how you would do it:
Bundle params = new Bundle();
params.putString("url", "http://img208.imageshack.us/img208/4834/pic1qu.png");
params.putString("caption", "Muslim Baby Names");
mAsyncRunner.request("me/photos", params, "POST");
Let me know if that helps!
Post to wall from Android application...
parameters.putString("app_id", mAppId);
parameters.putString("picture", "http://fbrell.com/f8.jpg");
parameters.putString("name", "Facebook Dialog");
parameters.putString("caption", "Reference Documentation");
parameters.putString("description", "Dialogs provide simple interface applications...");
parameters.putString("message", "Facebook Dialogs are easy!");
I have specified above parameters and every time I am getting blank dialog (with title "Post to your wall") - and when I click on "Publish" button - it post correct values on given account... so there is no issue relate to posing parameter values to wall, but I do not know why I am getting balnk dialog!
use simple facebook sdk project it simplifies things a lot.
They have created a library project for this
https://github.com/sromku/android-simple-facebook
I'm using facebook-android-sdk to post a message on facebook using the bundle shown below.
The message is displayed correctly, but the icon is not shown, and I can't find a way to get something like the image below.
Is this the correct way to set an icon?
How ca I add in the bundle something like "Get Spotify" as seen in the image?
Thanks.
Bundle params = new Bundle();
params.putString("message", "icon please");
params.putString("link", "http://www.digital-farm.org");
params.putString("name", "whip'em");
params.putString("description", "description");
params.putString("picture", "http://lib.store.yahoo.net/lib/yhst-17155638221985/img-twitter.gif"); //used for testing
params.putString("icon", "http://photos-c.ak.fbcdn.net/photos-ak-snc1/v27562/74/174829003346/app_2_174829003346_2760.gif"); //used for testing
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
mAsyncRunner.request("me/feed", params, "POST", new PostRequestListener(), null);
Actually that icon you show in your screen shot is probably the Facebook application's icon. It's set within the Facebook application's configuration/settings. When you post via your Facebook application, the icon should appear automagically. See screen shot below for example.
Assuming you're using the Facebook SDK for Android, when you instantiate your Facebook object, you pass your Facebook application's ID as parameter into the constructor. That's how the wall posting is associated with your Facebook application.