Facebook like button implementation in android - android

I know this question has been asked so many times.
In my app I also want to integrate Facebook like button,after doing lots of R&D I came across the below link
https://developers.facebook.com/docs/reference/opengraph/action-type/og.likes
and I am using the below code in my app,
Bundle params = new Bundle();
params.putString("object", "http://samples.ogp.me/226075010839791");
Request request = new Request(
Session.getActiveSession(),
"me/og.likes",
params,
HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response
but when I click the like button nothing is happening.
Could you all please guide me how to use the above code.
One more thing an extra permission is needed for implementing the above code "Permission: publish_actions".How to get this permission?

First open session with publish permission using this

Related

Android Facebook Like Button

Is it possible that I place a like button on my android app clicking which likes a post which is publicly available on facebook? I do not want any additional windows to open for the task except may be for first time authentication.
All questions asked so far are related to opening a new window.
It is possible. You can perform a Like Action using Facebook's Open Graph API. In order to do so, you need to meet certain conditions:
The viewer of the in-app content is a Facebook user who has Facebook-authed and granted the app publish_actions permission
The in-app content has an Open Graph object page that is properly marked-up using Open Graph metatags
The viewer has intentionally clicked on a custom in-app “like button” associated with the in-app content
Steps at a high-level:
You need to first get the user's active Session (com.facebook.Session).
Session session = Session.getActiveSession();
Then you need to ensure that the user has the publish_actions permission. If not, request them.
List<String> requestedPermissions = Arrays.asList("publish_actions");
List<String> currentPermissions = session.getPermissions();
if (!currentPermissions.containsAll(requestedPermissions)) {
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, requestedPermissions);
session.requestNewPublishPermissions(newPermissionsRequest);
}
Finally, send your request to "me/og.likes". Your request should include your Session, a Bundle including the Graph object you want to like, the HTTP method, and a callback that will execute once you receive a response.
Bundle postParams = new Bundle();
postParams.putString("object", myGraphObject);
Request request = new Request(session, "me/og.likes", postParams, HttpMethod.POST, myCallback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
You want to perform these steps in your button's OnClickListener.
Hope this helps!
Resources:
Like Action
Publishing Conditions

How to create and share facebook open graph stories in android

I have created a custom object called event and I would like people to perform an action called rsvp. I would like people to be able to share this action eg "Mary has rsvped to Some Event"
I have already created the action and configured the sentences now I just need a way to programatically be able to create events. I have tried using the code:
Bundle params = new Bundle();
GraphRequest request = new GraphRequest(
AccessToken.getCurrentAccessToken(),
"me/objects/my_namespace:event",
params,
HttpMethod.POST
);
GraphResponse response = request.executeAndWait();
But I keep getting the error "(#100) The parameter object is required".
My question is What is the step-by-step way from creating open graph stories to sharing them in Android? Also, what does that error mean?

Share to facebook from background - Android - Facebook SDK v4.x

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>() {...});

Post photo to Facebook parameters

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

Facebook post a message on a wall without open a dialog

I would like to post a message on the wall
this line works:
mFacebook.dialog(FacebookActivity.this, "post", new SampleDialogListener());
But i would like to post a message without open a dialog i tried this but get error which says mFacebook.request parameter mismatch
response = mFacebook.request("me/feed", parameters, "POST");
To post to a wall without a dialog you have to use the graph-api. Perform a feed post onto/with the userId of the target. To perform the Post you will have to need the publish_stream permission of the user. The returned accessToken of the permission-request has to be one of the post-parameters.
String response = mFacebook.request(Id+"/feed",bundle,HTTP_METHOD_POST);
But you have to check login before calling this method.Because it cannot check for login.
the code to login and it is single sign on.
mFacebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new ABCDialogListener());
and code to check session valid or not by
mFacebook.isSessionValid() method

Categories

Resources