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.
Related
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.
I write an android application which does a FB like to a FB post.
I succeed in doing it, but after a long time I get this response:
{
Response: responseCode: 400,
graphObject: null,
error:
{
HttpStatus: 400,
errorCode: 100,
errorType: OAuthException,
errorMessage: (#100) Error finding the requested story
},
isFromCache:false
}
for the code:
Request request = new Request(
session,
takeFromPublicMacrosOrServer(currentOffer.postId)
+ "/likes", null, HttpMethod.POST,
new Request.Callback() {
#Override
public void onCompleted(Response response) {
// Request complete
if (response.getError() == null) {
UnlockRequestToServer unlockRequestToServer = new UnlockRequestToServer(
mOffersListActivity,
PublicMacros.TYPE_UNLOCK_FB_LIKE,
currentOffer.postId);
} else {
final String errorMsg = "error: "
+ response.getError()
.toString();
Log.e(MyLogger.TAG, errorMsg);
if (BaseApplication
.getCurrentActivity() != null) {
BaseApplication
.getCurrentActivity()
.runOnUiThread(
new Runnable() {
public void run() {
if (PublicMacros.DEBUG) {
Toast.makeText(
BaseApplication
.getCurrentActivity(),
errorMsg,
Toast.LENGTH_LONG)
.show();
}
}
});
}
}
String re = response.toString();
}
});
request.executeAsync();
Does someone know how long is postId valid for FB like action ?
How do I get a page Access Token that does not expire? May contain some useful iformaion for you.
Facebook 3.0 How to post wall? Shows you how to post to your wall
This Question shows you the 'like' Facebook like in android using android.
EDIT
Facebook doesn't notify you that a previously issued access token has
become invalid. Unless you have persisted the expiry time passed to
your App along with the access token, your app may only learn that a
given token has become invalid is when you attempt to make a request
to the API. Also, in response to certain events that are
security-related, access tokens may be invalidated before the expected
expiration time.
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
Currently I call requestNewPublishPermissions to request the publish_stream permission.
Is there a way for me to see if the user has already authorized that permission so I don't need to ask it again?
I thought Session.isPublishPermission("publish_stream") might be that, but it doesn't seem to match the expected behavior.
To check if the user has already authorized a permission, you have to call the API:
\GET /me/permissions
You'll get the response in the format:
{
"data": [
{
"installed": 1,
"basic_info": 1,
"public_profile": 1,
"publish_stream": 1,
"user_notes": 1,
"user_friends": 1
}
],
}
If this have the "publish_stream": 1 permission that means the user has authorized the app to publish on his behalf.
Code (if using android SDK)-
new Request(
session,
"/me/permissions",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
I have a Bitmap image in my Android application and I need to upload it to the logged user's wall, including a caption message.
I've already implemented the Login button that (should) set-up the Session and, after a check with session.isOpened(), I call the method newUploadPhotoRequest(session, image, callback).
The problem is that the picture is never uploaded. Apparently, the login works because session.isOpened() return true after the user clicked on the Login Button. This means that API key, debug/release key hashes and all those stuffs are correct.
Instead, the callback of the upload method return this response:
{Response: responseCode: 200, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false}
Following: the code snippet behind the Activity (called FacebookActivity) that should upload the Bitmap.
private void startSending() {
((LinearLayout)findViewById(R.id.LoginLayout)).setVisibility(View.INVISIBLE);
((LinearLayout)findViewById(R.id.SendingLayout)).setVisibility(View.VISIBLE);
Request photoRequest = Request.newUploadPhotoRequest(Session.getActiveSession(), picture, new Request.Callback() {
#Override
public void onCompleted(Response response) {
Toast toast;
if(response.getError() == null) {
toast = Toast.makeText(getApplicationContext(), getString(R.string.ask_facebook_sent), Toast.LENGTH_LONG);
}
else {
// ERROR!
toast = Toast.makeText(getApplicationContext(), "Error! " + response.toString(), Toast.LENGTH_LONG);
}
toast.show();
finish();
}
});
Bundle requestParams = photoRequest.getParameters();
requestParams.putString("message", message);
photoRequest.setParameters(requestParams);
Request.executeBatchAsync(photoRequest);
}
Some considerations:
The picture is valid and visible
Facebook SDK is at the latest version (3.0.2)
I'm working on real device, with API level 8
In the Facebook Dev's Application page, I set the fields this way:
Package Name: com.ale.upmap (the app's namespace)
Class name: com.ale.upmap.FacebookActivity
Application has photo_upload permission enabled
Question: do I need to set permissions on the code too? Isn't it automatic? Also I didn't see any examples that use this method...