I'm trying to update my app to the new way to getting mutual friends from the facebook graph API v2.0.
On thier website here: https://developers.facebook.com/docs/graph-api/reference/v2.0/user.context/mutual_friends
they recommend to use this code:
Bundle params = new Bundle();
params.putString("fields", "context.fields(mutual_friends)");
/* make the API call */
new Request(
session,
"/{user-id}",
params,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
So I edited this code to put in the USER ID like so....
Bundle params = new Bundle();
params.putString("fields", "context.fields(mutual_friends)");
// make the API call
new Request(Session.getActiveSession(), "/{" + userProfile.getString("facebookId") + "}", params, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
System.out.println(response.toString());
}
}).executeAsync();
When I run the code, I get this error:
{Response: responseCode: 404, graphObject: null, error: {HttpStatus: 404, errorCode: 803, errorType: OAuthException, errorMessage: (#803) Some of the aliases you requested do not exist: {10102533400666784}}, isFromCache:false}
This alias does exist. What is wrong with my request?
The error response explains it
{Response: responseCode: 404, graphObject: null, error: {HttpStatus: 404, errorCode: 803, errorType: OAuthException, errorMessage: (#803) Some of the aliases you requested do not exist: {10102533400666784}}, isFromCache:false}
This alias {10102533400666784} does not exist remove the {}
Related
I need to get the age_range from facebook.
When i use /me?fields=age_range in my GraphRequest.newGraphPathRequest i get an error.
The error is that graphObject returns null. I've tried using /me and it works i get the correct user data though when i use /me?fields=age_range i get this error.
Testingļ¹ {Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 2500, errorType: OAuthException, errorMessage: An active access token must be used to query information about the current user.}}
This is the code i've been trying to fix.
GraphRequest request = GraphRequest.newGraphPathRequest(accessToken,
"/me?fields=age_range",
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
Log.v("Testing", graphResponse.toString());
}
});
request.executeAsync();
You should not put "/me?fields=age_range" as the path in your GraphRequest.
Instead, only use "/me" as the path, and then create a new Bundle, and put "fields" as the key, and "age_range" as a string value, and set the new bundle as the parameters on the GraphRequest.
GraphRequest request = ...
...
Bundle params = new Bundle();
params.putString("fields", "age_range");
request.setParameters(params);
request.executeAsync();
...
I am trying to read feed from public page, but I get this error:
Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 15, errorType: OAuthException, errorMessage: (#15) Requires session when calling from a desktop app}, isFromCache:false}
My steps:
1) get access token via https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=[APP_ID]&client_secret=[APP_SECRET]
2) create instance of AccessToken class: AccessToken token = AccessToken.createFromExistingAccessToken([TOKEN_FROM_STEP1], new Date(2015,3,2), new Date(), null, permissions);
3) open new session session = Session.openActiveSessionWithAccessToken(this, token, callback);
4) and make request:
new Request(session, "/[PUBLIC_PAGE_ID]/feed", null, HttpMethod.GET, new Request.Callback() {
public void onCompleted(Response response) {
//check response
}
}).executeAsync();
Where is mistake? What is the right way?
The "Native or Desktop app" setting is disabled for this app.
Session currentSession = Session.getActiveSession();
if (currentSession.isOpened()) {
Request req = new Request(currentSession, "/me/friends?fields=id,name,installed,picture",null, HttpMethod.GET,
new Callback() {
#Override
public void onCompleted(Response response)
{
//CODE..
}
});
Request.executeBatchAsync(req);
}
Got response like this.
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 2500, errorType: OAuthException, errorMessage: An active access token must be used to query information about the current user.}, isFromCache:false}
Whats wrong with this code.
Permission provided are
"publish_stream","user_likes","email","user_birthday","user_interests","user_friends"
Got the result.Thanks #Jesse Chen
Bundle params() = new Bundle();
params.putString("fields", "id,name,installed,picture");
Request req = new Request(session, "me/friends", params, HttpMethod.GET..
I retrieved all the posts from my Facebook wall but now I want to like the post using the post_id. I am using following code but getting below mentioned exception
{Response: responseCode: 200, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false}
My code:
Request likeRequest = new Request(Session.getActiveSession(), fBPostId + "/likes", null, HttpMethod.POST, new Request.Callback()
{
#Override
public void onCompleted(Response response)
{
Log.d("Like clicked",response.toString());
}
});
Request.executeBatchAndWait(likeRequest);
You should grant "publish_actions" permission to do that.
If you are using LoginButton :
loginButton.setPublishPermissions(Arrays.asList("publish_actions"));
When trying to post an activity to Facebook from a native Android application, I get the following response after executing the request:
{
Response: responseCode: 200,
graphObject: null,
error: {
HttpStatus: -1,
errorCode: -1,
errorType: null,
errorMessage: null
},
isFromCache: false
}
My app gets the publish_action permission from the user.
public void publishActivity(){
session = Session.getActiveSession();
openSession();
Bundle params = new Bundle();
params.putString("highest", "http://www.my-url.com/graph.html");
Request request = new Request(
Session.getActiveSession(),
"me/namespace:play",
params,
HttpMethod.POST
);
Response response = request.executeAndWait();
Log.d("DEBUG",response.toString());
}
public void openSession(){
if(session.isClosed()){
Session.OpenRequest openRequest = new Session.OpenRequest(GameActivity.get());
openRequest.setPermissions(PERMISSIONS);
session.openForPublish(openRequest);
}
}
(I replaced the url and the namespace. In my code, they are correct.)
The problem appeared to be in the KeyHash provided by the namespace. It had changed, and it was not added in the Facebook Developers page yet.