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.
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 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.
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/
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 have tried to do a FB like from my android app
where the user must sign in with FB.
But I got this error in FB response:
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 283, errorType: OAuthException, errorMessage: (#283) Require extended permission: manage_pages}, isFromCache:false}
Why is "manage_pages" permission needed anyway?
I'm an Admin of page in which the post exist.
I then tried to ask additional permission from the user "manage_pages"
but I still get the same error.
private void onSessionStateChange(Session session, SessionState state,
Exception exception) {
List<String> permissions = session.getPermissions();
if (permissions.size() > 0 && !permissions.contains("publish_actions")) {
requestPublishPermissions(this, session,
Arrays.asList("publish_actions", "manage_pages"),
PublicMacros.REQUEST_CODE_PUBLISH_PERMISSIONS);
}
public static void requestPublishPermissions(Activity activity,
Session session, List<String> permissions, int requestCode) {
if (session != null) {
Session.NewPermissionsRequest reauthRequest = new Session.NewPermissionsRequest(
activity, permissions).setRequestCode(requestCode);
session.requestNewPublishPermissions(reauthRequest);
}
}
This is the code that does FB like:
Request request = new Request(
session,
takeFromPublicMacrosOrServer(currentOffer.fbPostId)
+ "/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.fbPostId);
// (4) unlock 4 - skip
sendUnlockRequestToServer(
unlockRequestToServer,
currentLockView);
} 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();
}
If you are using Graph API v2.0 or higher, your app needs to be review if you use extended permissions like manage_pages to be able to use this with other users than app admins or developers.
I suspect that this is your problem.
Have a look at my answer here: Facebook me/feed can only post on developers account only