Like a post using facebook Sdk 3 - android

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"));

Related

Facebook Graph Api search in android

Just want to search all the events in a particular location by using new request in graph api,but error throws.
//Request for events
new Request(
session,
"/search?q=dubai&type=event",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
System.out.println("Result: " + response.toString());
}
}
).executeAsync();
Permission:-
authButton.setPublishPermissions("publish_actions","manage_pages");
output:-
Result: {Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 100, errorType: GraphMethodException, errorMessage: Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api}, isFromCache:false}
suggest some way to solve it.
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{event-id}",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
Hope it will help you, for detail go through below link
https://developers.facebook.com/docs/graph-api/reference/event/
Try this new API, hope this help you.
Graph Event API
Graph API
for facebook Api, please refer below its developer link:
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2
https://developers.facebook.com/docs/graph-api/reference
http://api-portal.anypoint.mulesoft.com/facebook/api/facebook-graph-api/docs/code
I hope it work.

Android facebook api How to read feed from public page without login?

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.

Android Getting Facebook Mutual Friends How To Fill In USER ID?

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 {}

Android New Facebook SDK Exception in Graph Request

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..

Empty graphobject on OG request

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.

Categories

Resources