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
Related
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
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 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
I am working on an Android app where we enter some text in edit box. All I want to do is simply send the text which typed (i.e. edittext.gettext()) to Facebook as my status. The important thing is I don't want a Facebook dialog box to pop up, instead, just send the message as status without a dialog box. Is there any way I could post without a dialog box?
I am not sure this is use full to you,
mAsyncRunner.request(null, params, "POST", new PhotoUploadListener(), null);
mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null);
And still if your problem exists because of an existing Facebook app in the device, then you might have make the login compulsory.
In this piece of your code,
do this
public void loginAndPostToWall(){
facebook.authorize(this, PERMISSIONS,-1, new LoginDialogListener());
}
It should do the trick.
I am trying to update a notification via the Facebook ADK. The documentation says this:
"You can mark a notification as read by issuing an HTTP POST request to /NOTIFICATION_ID?unread=0 with the manage_notifications permission."
I know how to read the notifications with the graph path "me/notifications", but I am unsure of the code to do a POST to mark a notification as being read.
Facebook facebook = ......."Authorized Facebook Object"
Bundle parameters = new Bundle();
parameters.putString(Facebook.TOKEN, accessToken);
...
How do I add in the "/NOTIFICATION_ID?unread=0" parameters?
...
String result = facebook.request("me/notifications", parameters, "POST");
Thanks.
Ok...I figured this one out:
Facebook facebook = ...
String unreadParameter = "0";
Bundle parameters = new Bundle();
parameters.putString(Facebook.TOKEN, accessToken);
parameters.putString("unread", unreadParameter);
String result = facebook.request(notificationID, parameters, "POST");
The Graph Path needs to only be the "NOTIFICATION_ID" and nothing else...I was putting in "me/notifications/NOTIFICATION_ID" and other variations.
I hope that others find this helpful.