Hi i have been trying to find how to add the like button to my android code. i have done the following things can anyone help me out it always throw me this error
{Response: responseCode: 403, graphObject: null, error: {HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) Requires extended permission: publish_actions}, isFromCache:false}
i have added the publish permission in my request as wel. my code below:
public void doLike(Session session, String Id) {
Bundle params = new Bundle();
params.putString("object", "http://graph.facebook.com/" + Id);
// /* make the API call */
new Request(session, "/me/og.likes", params, HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
// /* handle the result */
System.out.println(response);
}
}).executeAsync();
}
{Request: session: {Session state:OPENED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[publish_actions, publish_stream]}, appId:xxxxxx}, graphPath: /me/og.likes, graphObject: null, restMethod: null, httpMethod: POST, parameters: Bundle[{access_token=CAAT0aKyquLEBAOxF4XYENsZBFLdD7ZALvGOvQ25ZAvGl6vmCPz8AHOQcZAnKHaOOYPv4DkL0VlMu7jveZCjmht20MuB7qLWpUZAo2DPQxG16ZAF5ICouzAbwpKmMmJdEF1HN1MzCLp5GhlYyy4f63WL5wUE21wRKiYg8wJVy3AGlATcDjpU4FyZB64dZCDv66zv228ZCsuemiFIqf5Qqwcb1QIca91WfCCDZCh71ZCz9CXegCvt1CBurddDo, format=json, object=http://graph.facebook.com/xxxx, sdk=android}]}
this is my request but still getting the error
Just follow the screenshot and check did you set the above permissions?
Related
I want to get fan page news/feeds without user login and without access token. in this question I found that you don't need any access token. if you have App-ID and App-Secret. This solution works on browser but doesn't on Android app.
Here is my code sample:
new GraphRequest(null,
"https://graph.facebook.com/{group_id}/feed?access_token={app_id}|{app_secret}",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
Log.d("Facebook_feed", response.toString());
}
}).executeAsync();
Here my response:
{
Response: responseCode: 400,
graphObject: null,
error: {
HttpStatus: 400,
errorCode: 190,
errorType: OAuthException,
errorMessage: Invalid OAuth access token signature.
}
}
Why this happen?
Using This code for getting event:-
new Request(session,"/{event-id}",null,HttpMethod.GET,new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
System.out.println("Result: " + response.toString());
}
}).executeAsync();
}
});
Permission :---
authButton.setReadPermissions(Arrays.asList("user_location", "user_birthday", "user_likes","user_events","read_stream"));
And it gave me error :----
I/System.outīš Result: {Response: responseCode: 404, graphObject: null, error: {HttpStatus: 404, errorCode: 803, errorType: OAuthException, errorMessage: (#803) Some of the aliases you requested do not exist: {event-id}}, isFromCache:false}
The error message explains it
(#803) Some of the aliases you requested do not exist: {event-id}
new Request(session,"/{event-id}",null,HttpMethod.GET,new Request.Callback()
There should be an actual event ID or at least a variable that holds the value of an event ID.
I am using facebook sdk for login in android app. my code working fine for login facebook in android app. but then i used facebook like action using facebook sdk error is occured. The error is below
{Response: responseCode: 403, graphObject: null, error: {HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) You do not have sufficient permissions to perform this action}, isFromCache:false}}, isFromCache:false}
And the code is:-
String grapPath = String.format("%s/likes", postID);
Request request = new Request(Session.getActiveSession(), grapPath,
null, HttpMethod.POST, new Request.Callback() {
#Override
public void onCompleted(Response response) {
String res = response.toString();
Log.i("********************************", res
+ " Success!");
}
});
Request.executeBatchAsync(request);
Please help me for solve this problem.
the error is quite clear , you do not have the required permission to post ,
while logging the user , ask for the relevant permission "publish_actions"
For more info --> https://developers.facebook.com/docs/facebook-login/permissions
I have this code:
public class LikeFbPostAsyncTask extends AsyncTask<String, Void, Void> {
ImageButton mLockImage;
Response fbServerResponse;
public LikeFbPostAsyncTask(ImageButton lockImage) {
mLockImage = lockImage;
}
#Override
protected void onPreExecute() {
Log.i("LikeFbPostAsyncTask", "Starting web task...");
}
#Override
protected Void doInBackground(String... fbPostId) {
Request likeRequest = new Request(Session.getActiveSession(),
fbPostId[0] + "/likes", null, HttpMethod.POST,
new Request.Callback() {
// here is non-ui thread
#Override
public void onCompleted(final Response response) {
Log.i(TAG, response.toString());
fbServerResponse = response;
}
});
Request.executeBatchAndWait(likeRequest);
return null;
}
}
for submitting FB like.
This is the request to FB server:
{Request: session: {Session state:OPENED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[email, user_birthday, user_location, user_likes, user_interests, user_friends, user_status, basic_info]}, appId:1313----0364547}, graphPath: 685560152_10153987123125153/likes, graphObject: null, restMethod: null, httpMethod: POST, parameters: Bundle[{migration_bundle=fbsdk:20131203}]}
and I get the following error:
errorMessage: (#200) You do not have sufficient permissions to perform this action
How can i get a sufficient permission?
update
I have tried #serge solution
and added "users_like to app in Fb pgae under app center permissions
Now I get this error:
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 2000, errorType: OAuthException, errorMessage: (#2000) The publish_likes feature is disabled for this application.}, isFromCache:false}
Under your app on Facebook Developers, go to App Details and click Configure App Center Permissions. Then make sure that you have corresponding permissions under App Center Permissions.
updated: I think you need to add publish_likes tag as well
I am using the updated Facebook SDK V3.0 final for Android. I am trying to send app requests to facebook frineds who do not have the application. The code is:
public void fbookinvite(){
Bundle postParams = new Bundle();
postParams.putString("name", "X");
postParams.putString("message", "DOWNLOAD X.");
Session session = Session.getActiveSession();
postParams.putString("access_token", session.getAccessToken());
if (session==null||session.getState().isClosed()){
System.out.println("session is null");
}else{
//meaning we are good to go.
Request request = new Request(session,"/friend facebook id/apprequests", postParams, HttpMethod.POST, new Request.Callback() {
#Override
public void onCompleted(Response response) {
System.out.println("response was: "+response.toString());
}
});
Request.executeBatchAsync(request);
}
}
When the code runs I get one of the following from the printed response:
responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 2, errorType: OAuthException, errorMessage: (#2) Failed to create any app request}, isFromCache:false
... or:
Response: responseCode: unknown, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false}
I have the following permissions: publist_stream and publish_actions.
After solving the problem I'd also like to know how to add a group of recipients to the app request.
I do not want to use the Facebook dialog.
Try this instead:
Bundle params = new Bundle();
params.putString("message",
"Learn how to make your Android apps social");
params.putString("to", "YOUR_FRIEND_UID_HERE");
WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(
this, Session.getActiveSession(), params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
// your code here
}
}).build();
requestsDialog.show();
This is the proper way to send an app request explicitly to someone. If you do not include the to parameter, the user can choose who they want to send to.
Response: responseCode: unknown, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false}
This is a scenario usually related with running simultaneous FB requests on your own threads.
I learnt the hard way to use either
Request.executeAsync()
or
RequestAsyncTask