Facebook Post Like action not working in Android - android

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

Related

How to get facebook fan page feed

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?

Upload Video To Facebook from my android app fail with error extended permission requiren status 403

In MY android app i want to share video from android app to facebook wall.
Below is my code for doing so-
Request.Callback callback5 = new Request.Callback() {
public void onCompleted(Response response) {
Toast.makeText(mContext,"Success",Toast.LENGTH_SHORT).show();
mDialog.dismiss();
}
};
File mFile = new File(videoPath);
Request request5;
try {
request5 = Request.newUploadVideoRequest(session,
mFile, callback5);
RequestAsyncTask task5 = new RequestAsyncTask(request5);
task5.execute();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Also made changes in fb api console.But when upload video-
{Response: responseCode: 403, graphObject: null, error: {HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) Requires extended permission: publish_actions}, isFromCache:false}
Edit: Permissions i have added-
` Session s = new Session(mContext);
Session.setActiveSession(s);
s.openForPublish(new Session.OpenRequest(PostVideoToFBWall.this).setCallback(callback).setPermissions("public_profile","email","publish_actions"));`

Cannot read a facebook event with graph API from android app

I ma trying to read facebook event's details from an ANdroid application by using this code :
new Request(
session,
"me/events/created",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
System.out.println("Result: " + response.toString());
}
}
).executeAsync();
but I m always receiving a ampty response :
Result: {Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[]}}, error: null, isFromCache:false}
Although when i tried the Graph API Explorer https://developers.facebook.com/tools/explorer i get the right list !!!!
Have you configured the correct permissions for your app? To get the User's Events, you need to aquire the user_events permission upon login.
See https://developers.facebook.com/docs/graph-api/reference/v2.0/user/events/#readperms

Facebook Like Button Android native

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?

Apprequest of Android Facebook sdk 3.0

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

Categories

Resources