Cannot read a facebook event with graph API from android app - android

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

Related

Facebook Graph request Android name from user ID

I'm trying to get the name of a user from his user ID.
on this link they say that we can do it from a simple HTTP request like that:
http://graph.facebook.com/4
But it seems that this method is outdated because i cant get anything because:
"An access token is requir…o request this resource."
Anyway i tried using their documentation about the graph api on Android and i did it like that:
GraphRequestAsyncTask request1 = new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/"+id1+"/name",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
name1.setText(request1.toString());
But on the name1 TextView i get a message that tells me
{RequestAsyncTask:
connection:null,requests:[{Request:
accesToken:{AccessToken
token:ACCESS_TOKEN_REMOVED permissions:
[public_profile]},
graphPath:/100017723671435/name, graphObject: null,
httpMethod:Get,
parameters:Bundle[{}]}]}
I don't really understand how to do, i have a bunch of facebook ID's on my database and i just want to get the name from the ID, to display it on the screen.
The current user of the app is not the profile which i want to get the infos!
EDIT: It seems i misunderstood the /*handle the result*/ commentary, i made this line like that:
name1.setText(response.toString());
But i have still an error on my TextView:
{Response:
responseCode:400,
graphObject:null,
error: { HttpStatus:400,
errorCode: 2500,
errorType: OAuthException,
errorMessage: Unknown path components: /first_name }}
So it seems i don't use the Graph Paths properly. I'm still looking on the doc and on Google, if i find the answer i'll give the code!
Ensure that you are logged in with read permission.
If you are logged in you can try with:
GraphRequest.Callback gCallback = new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
Log.d(TAG, "onCompleted: ");
if (response != null && response.getJSONObject() != null && response.getJSONObject().has("first_name"))
{
try {
name1.setText(response.getJSONObject().getString("first_name"));
} catch (JSONException e) {
Log.e(TAG, "onCompleted: ",e );
}
}
}
};
new GraphRequest(AccessToken.getCurrentAccessToken(),"/me?fields=id,name,gender,email,first_name,last_name", null,HttpMethod.GET, gCallback).executeAsync();
If you have a problem with login, maybe this link can help you.

Facebook Post Like action not working in 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

Facebook FriendPickerFragment api

I have downloaded facebook-android-sdk-3.14.1.zip and am trying to get the examples working. I get stuck on the FriendPickerFragment that never returns a list of friends. I can log onto Facebook ok (again using the Facebook code), both using the 'Scrumptious' example and my version of it by followiing https://developers.facebook.com/docs/android/getting-started
I found that my requests were only going with public profile permission e.g.
{Session state:OPENED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[public_profile]}, appId:520510648055719}
I took code from Facebook friend picker SDK sample not working Android, that would add the user_friends permission and see that Session was now:
{Session state:OPENED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[public_profile, basic_info, user_friends]}, appId:520510648055719}
When I traced the code down to RequestAsyncTask.doInBackground the values of requests in :
#Override
protected List<Response> doInBackground(Void... params) {
try {
if (connection == null) {
return requests.executeAndWait();
} else {
return Request.executeConnectionAndWait(connection, requests);
}
} catch (Exception e) {
exception = e;
return null;
}
}
is
{Request: session: {Session state:OPENED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[public_profile, basic_info, user_friends]}, appId:520510648055719}, graphPath: me/friends, graphObject: null, restMethod: null, httpMethod: GET, parameters: Bundle[{fields=id,name,picture.height(75).width(75)}]}
and I see as a response in onPostExecute(List result) :
[{Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[]}}, error: null, isFromCache:true}]
Could there have been some caching problem earlier that I need to clear first? If so how do I do that?
I have read that Facebook has changed security recently. I have create my Facebook TestUI 'app' and entered the hashKey (I assume all is ok as I can log into Facebook successfully)
Is there something else I should be looking at?
Looking for any and all wisdom on this.
Thanks
Eric
With Graph Search v2.0, requests for a user's friends will only return a list of friends that also use your app (including the samples), and the user_friends permission must be requested as a special permission. There doesn't appear to be a true way around this, though you can search for things like "taggable_friends" using something like:
new Request(
session,
"/me/taggable_friends", //instead of "/me/friends"
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}).executeAsync();
from Facebook Graph Reference.

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?

Posting image on friends wall using fb android sdk 3.0

i m trying to post images on friends fb wall, im getting selected friend ID,
and image that is converted in base64 string
just getting response as error below
{Response: responseCode: 200, graphObject: null, error: {HttpStatus: 200, errorCode: 3, errorType: null, errorMessage: Unknown method}, isFromCache:false}
my code below
if (hasPublishPermission()) {
Request postToWall = new Request();
for (GraphUser friend : selectedFriends) {
Constants.showLog("Selected Frnd", friend.getId());
Constants.showLog("Selected Pic", picture);
Bundle parameters = new Bundle();
parameters.putByteArray("message", "Greetings from Wish Well!".getBytes());
parameters.putByteArray("link", "http://pictwist.cloudganga.com".getBytes());
parameters.putByteArray("picture", picture.getBytes());
parameters.putByteArray("target_id", friend.getId().getBytes());
postToWall = Request.newRestRequest(Session.getActiveSession(), friend.getId() + "/feed", parameters, HttpMethod.POST);
Constants.showToast(getApplicationContext(), "Posted image on friend wall");
}
postToWall.setCallback( new Request.Callback()
{
#Override
public void onCompleted(Response response)
{
Constants.showLog("Responce Posting image", response.toString());
}
});
Request.executeBatchAsync(postToWall);
}
please help
Posting image or any content on friend's walls is no more supported by the sdk since feb 6, 2013. You need to use the feed dialog to do that..
check this link..
https://developers.facebook.com/roadmap/completed-changes/

Categories

Resources