I'm trying to retrieve a friend's albums with the following code. Both the account I'm logged in and the one whose albums I'm trying to get are Test Users, so permissions shouldn't be an issue. I retrieve selectedUsers with a friend picker. But eventually i get this error,
12-18 02:18:32.969: D/error(4182): {HttpStatus: 404, errorCode: 803, errorType: OAuthException, errorMessage: (#803) Some of the aliases you requested do not exist: AaJHRMAiukD_rQWiC-K_RXMEjTWzGjJO-dx6QwonppGEcaNlUL4YKLn80pepf-pXHkrgVNYnPktnH25czlD5eIhkXrtlFN8qQZB1UhhXPEAgAA}
as well as a NullPointerException at getInnerJSONObject line.
String grPath = "/"+selectedUsers.get(0).getId()+"/albums";
RequestAsyncTask req = new Request(Session.getActiveSession(),grPath,null, HttpMethod.GET, new Request.Callback() {
#Override
public void onCompleted(Response response) {
if(null != response.getError()){
Log.d("error", response.getError().toString());
}
GraphObject responseGraphObject = response.getGraphObject();
JSONObject json = responseGraphObject.getInnerJSONObject();
try {
JSONArray jarr = json.getJSONArray("data");
for(int i =0;i<jarr.length();i++){
String name= jarr.getJSONObject(i).getString("name");
String albid= jarr.getJSONObject(i).getString("id");
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Did you create your app after 4/30/2014? If so, you're on version 2.x of the Graph API, and you can no longer get the photos of a friend. You can only access the photos of the user who has logged in and authorized your app. This is what #WizKid was referencing.
What you're seeing from selectedUsers.get(0).getID is from the taggable_friends endpoint, which gives you a one-time, obfuscated String id, and you should not try to use it for anything other than to tag friends (like when you're uploading a photo).
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.
Code i used for fetching the list after doing some search is below
GraphRequestBatch batch = new GraphRequestBatch(
GraphRequest.newMyFriendsRequest(
accessToken,
new GraphRequest.GraphJSONArrayCallback() {
#Override
public void onCompleted(
JSONArray jsonArray,
GraphResponse response) {
// Application code for users friends
System.out.println("getFriendsData onCompleted : jsonArray " + jsonArray);
System.out.println("getFriendsData onCompleted : response " + response);
try {
JSONObject jsonObject = response.getJSONObject();
System.out.println("getFriendsData onCompleted : jsonObject " + jsonObject);
JSONObject summary = jsonObject.getJSONObject("summary");
System.out.println("getFriendsData onCompleted : summary total_count - " + summary.getString("total_count"));
} catch (Exception e) {
e.printStackTrace();
}
}
})
);
batch.addCallback(new GraphRequestBatch.Callback() {
#Override
public void onBatchCompleted(GraphRequestBatch graphRequests) {
// Application code for when the batch finishes
}
});
batch.executeAsync();
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link,picture");
and the permission i get is
accessToken : {AccessToken token:ACCESS_TOKEN_REMOVED permissions:[user_friends, basic_info]}
getRecentlyGrantedPermissions : [user_friends, basic_info]
getRecentlyDeniedPermissions : []
and the output of the graph function is -
response {Response: responseCode: 200, graphObject: {"summary":{"total_count":3},"data":[]}, error: null}
so can anyone please guide me to fetch the friend list of user .
Thanx in advance .
The output is correct, none of your friends authorized your App yet. Since v2.0 of the Graph API you can only get the friends who authorized your App, for privacy reasons: https://developers.facebook.com/docs/graph-api/reference/v2.3/user/friends
More information can be found in this thread: Get ALL User Friends Using Facebook Graph API - Android
I have an android app with facebook sdk api integration that allow user to login to facebook and share picture. I've tested my android app by log in with my facebook account (my account is the owner of facebook app) and everithing work well. But if i log in with another account (that is not owner of Facebook app) i'm not able to upload picture. I receive this error;
12-04 13:35:33.484: I/FACEBOOK(20673): {HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) Permissions error}
i update picture in this way:
final ProgressDialog spinner = new ProgressDialog(this);
// Part 1: create callback to get URL of uploaded photo
Request.Callback uploadPhotoRequestCallback = new Request.Callback() {
#Override
public void onCompleted(Response response) {
String alert_title = "";
String alert_message = "";
if (response.getError() != null) {
Log.i("FACEBOOK", response.getError().toString());
alert_title = FullPics.this.getString(R.string.alert_error);
alert_message = FullPics.this
.getString(R.string.publish_pic_fail);
} else {
Object graphResponse = response.getGraphObject()
.getProperty("id");
if (graphResponse == null
|| !(graphResponse instanceof String)
|| TextUtils.isEmpty((String) graphResponse)) {
Log.d("FULL", "failed photo upload/no response");
alert_title = FullPics.this
.getString(R.string.alert_error);
alert_message = FullPics.this
.getString(R.string.publish_pic_fail);
} else {
alert_title = FullPics.this
.getString(R.string.alert_success);
alert_message = FullPics.this
.getString(R.string.publish_pic_success);
}
}
spinner.dismiss();
showMessage(alert_title, alert_message);
}
};
File image_file = fragmentAdapter.getCurrentImageFile(pager
.getCurrentItem());
Request request;
try {
spinner.setMessage(getString(R.string.publish_pic_in_progress));
spinner.setCancelable(false);
spinner.setCanceledOnTouchOutside(false);
spinner.setProgressStyle(ProgressDialog.STYLE_SPINNER);
spinner.show();
request = Request.newUploadPhotoRequest(
Session.openActiveSession(this, false, null), image_file,
uploadPhotoRequestCallback);
request.executeAsync();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
what's wrong? maybe i need to set something on Facebook developer site inside my app?
This is happening because your facebook app is private to you only. If you observe your app on facebook there will be little green circle which will be shown as disabled if your api is private.
It should public and filled with green color. Then only other user can use this app.
Visit https://developers.facebook.com/docs/games/bestpractice/managing-development-cycle?locale=en_GB for more info
according to new facebook sdk, you need to submit your app for review if you are publishing anything.
after facebook approval you can upload picture by using any login.
you can check this link for review process
https://developers.facebook.com/docs/apps/review/
https://github.com/sauce/guide/wiki/Facebook's-approval-process
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'm trying to fetch data in my Android-App from Facebook via FQL multiquery like discribed here: http://www.kanatorn.info/2011/12/31/fql-multiple-query-android-sdk-example/
here's my code:
Bundle params = new Bundle();
JSONObject multiquery = new JSONObject();
try {
multiquery.put("query1", "SELECT eid, name, start_time, is_date_only, pic_square, pic_big, location FROM event WHERE eid IN" +
"(SELECT eid FROM event_member WHERE uid=me() AND start_time >= now()) ORDER BY start_time");
multiquery.put("query2", "SELECT eid, rsvp_status, start_time FROM event_member WHERE uid=me() AND start_time >= now() ORDER BY start_time");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
params.putString("method", "fql.multiquery");
params.putString("queries", multiquery.toString());
Session session = Session.getActiveSession();
Request request = new Request(session,
"/fql",
params,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(Response response) {
...
}
});
Request.executeAndWait(request);
the result I'm getting is the following:
{Response: responseCode: 500, graphObject: null, error: {HttpStatus: 500, errorCode: -1, errorType: Exception, errorMessage: Unsupported method, fql.multiquery}, isFromCache:false}
I can't figure out where my mistake is. It says unsupported method, multiquery, but this actually should be a valid method, right? I looked everywhere for a similiar problem but it seems that I'm alone with that issue.
I have the feeling that I'm missing something simple...
Would be cool if someone can help me out. Thanks!
btw. with normal queries everything works fine.
The linked Kanatorn page says method should be fql.multiquery, but you have just multiquery.
To solve this
have you read this developers page.
http://developers.facebook.com/docs/howtos/androidsdk/3.0/run-fql-queries/
Updated url
https://developers.facebook.com/docs/android/graph/#fql