Android error getting Facebook friends with some users - android

I'm trying to get the friends from facebook, but when I'm try with my personal account I get the friends that I have and uses the app. The problem is when I use an other account (this account has my personal account as friend) the app doesn't get the friends.
This is my code:
if (session.isOpened() && hasFriendsPermission()) {
Request friendRequest = Request.newMyFriendsRequest(session,
new GraphUserListCallback(){
#Override
public void onCompleted(List<GraphUser> users,
Response response) {
Log.i("INFO", response.toString());// + " - " + users.size());
friends = users;
if (friends != null && friends.size() > 0) {
if (processTask == null) {
processTask = new FriendsProcess();
processTask.execute();
}
}
}
});
Bundle params = new Bundle();
params.putString("fields", "id,name");//,friends");
friendRequest.setParameters(params);
friendRequest.executeAsync();
}
And this is the response I'm getting in the other account (the account that's not my personal facebook account):
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 100, errorType: OAuthException, errorMessage: Unsupported operation}, isFromCache:false}
I hope you can help me to fix this, or at least to know why this is happening. Thanks!

When your application is in sandbox/development mode you can not perform any api call for other user. To test your for other user, add the user as a tester, developer or admin. See details https://developers.facebook.com/docs/ApplicationSecurity/

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.

permission error while posting custom story by FacebookSDk 4.0 in android

I want to post a custom story by FacebookSDK 4.0 My Application is also approved by facebook. but my problem is when I post story as a developer/admin role then the custom story successfully gets posted on facebook but custom story post as a simple user(who is not developer/admin) it gives permission error. like
I/System.out(30594): ResponseCustomStory{Response: responseCode: 500, graphObject: null, error: {HttpStatus: 500, errorCode: 200, errorType: FacebookApiException, errorMessage: Permissions error}}
and AccessToken debug in logcat like this
AccessToken token:ACCESS_TOKEN_REMOVED permissions:[user_friends, public_profile, publish_actions]}
my code is here>
Before this I am already logged.
FacebookSdk.sdkInitialize(activity);
AccessToken access_token = AccessToken.getCurrentAccessToken();
System.out.println("access_tokenincompleate" + access_token);
SharedPreferences sp = activity.getSharedPreferences("profile",
Context.MODE_PRIVATE);
String pro_name = sp.getString("profileName", null);
if (access_token != null) {
if (hasPublishPermission()) {
// We can do the action right away.
handlePendingAction();
} else {
// We need to get new permissions, then complete the action when
// we get called back.
LoginManager.getInstance().logInWithPublishPermissions(
activity, Arrays.asList(PERMISSION));
}
}
Bundle params = new Bundle();
if(level == 1){
params.putString("message",pro_name +" has completed " + level
+ "st Level in Sosh");
}else{
params.putString("message",pro_name +" has completed " + level
+ "st Level in Sosh");
}
// params.putString("level", "10");
params.putString("level","http://ses.com/fbobjects/sbc_applink.php");
// http://segs.com/fbobjects/customstory.html
new GraphRequest(access_token, "me/namespace:complete", params,
HttpMethod.POST, new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
System.out.println("ResponseCustomStory" + response);
}
}).executeAsync();
I submitted my game for review and it is approved and Live (for Publish_action permission).
Please help if someone has faced similar issue.

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

Unable to upload picture to facebook From android app with different user than me

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

how long is the FB postId expiration date?

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.

Categories

Resources