I am getting this error message while trying to open the facebook page of the user.The strange thing is that if I have a mutual friend with that user the page loads with no problem, but I don't think it's default behavior, otherwise I can't understand the meaning of user_link permission.
Facebook has approved user_link permission and I passed App Review.
From developer account I changed the API version the app calls to v3.1.
The way I am getting user_link
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("user_gender", "user_link"));
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
makeGraphRequest(loginResult.getAccessToken());
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
}
});
public void makeGraphRequest(AccessToken token) {
GraphRequest request = GraphRequest.newMeRequest(
token, (object, response) -> {
try {
userStorage.setUserProfileUrl(object.getString(AppConstants.LINK));
} catch (JSONException e) {
e.printStackTrace();
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "name,gender,link,picture.width(700).height(700)");
request.setParameters(parameters);
request.executeAsync();
}
And using this answer for opening the page.
Intent intent;
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=" + currentUser.getLink()));
context.startActivity(intent);
} catch (Exception e) {
intent = new Intent(context, FacebookWebViewActivity.class);
intent.putExtra(AppConstants.USER_LINK, currentUser.getLink());
context.startActivity(intent);
}
build.gradle
implementation 'com.facebook.android:facebook-login:4.33.0'
I will be very thankful if someone can suggest any solution. I faced this issue before the facebook new API version also.
From this post we can find the following bit of text
For most apps, links will only redirect to the individual's Facebook
profile for logged in people in the person's extended network.
So, I guess there is no way to be 100% sure that the user page will be loaded properly.
https://developers.facebook.com/docs/graph-api/changelog/version3.0#login
...the following fields that belonged to public_profile are deprecated...
As you can read in the changelog, the "link" and "gender" fields are deprecated.
Edit: But they have introduced new permissions user_link and user_gender so that users can explicitly asked for those particular fields. (Thanks to CBroe for pointing that out)
Related
I am getting this error message while trying to open the facebook page of the user.The strange thing is that if I have a mutual friend with that user the page loads with no problem, but I don't think it's default behavior, otherwise I can't understand the meaning of user_link permission.
Facebook has approved user_link permission and I passed App Review.
From developer account I changed the API version the app calls to v3.1.
The way I am getting user_link
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("user_gender", "user_link"));
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
makeGraphRequest(loginResult.getAccessToken());
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
}
});
public void makeGraphRequest(AccessToken token) {
GraphRequest request = GraphRequest.newMeRequest(
token, (object, response) -> {
try {
userStorage.setUserProfileUrl(object.getString(AppConstants.LINK));
} catch (JSONException e) {
e.printStackTrace();
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "name,gender,link,picture.width(700).height(700)");
request.setParameters(parameters);
request.executeAsync();
}
And using this answer for opening the page.
Intent intent;
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=" + currentUser.getLink()));
context.startActivity(intent);
} catch (Exception e) {
intent = new Intent(context, FacebookWebViewActivity.class);
intent.putExtra(AppConstants.USER_LINK, currentUser.getLink());
context.startActivity(intent);
}
build.gradle
implementation 'com.facebook.android:facebook-login:4.33.0'
I will be very thankful if someone can suggest any solution. I faced this issue before the facebook new API version also.
From this post we can find the following bit of text
For most apps, links will only redirect to the individual's Facebook
profile for logged in people in the person's extended network.
So, I guess there is no way to be 100% sure that the user page will be loaded properly.
https://developers.facebook.com/docs/graph-api/changelog/version3.0#login
...the following fields that belonged to public_profile are deprecated...
As you can read in the changelog, the "link" and "gender" fields are deprecated.
Edit: But they have introduced new permissions user_link and user_gender so that users can explicitly asked for those particular fields. (Thanks to CBroe for pointing that out)
Facebook just driving me crazy! I have no idea, what they are trying to get from me. The thing is that I want to is to make SHARE button inside my Android app. What code I should write in order to get similar window?
This is the pic what I wanna do:
http://s29.postimg.org/pvgbhv1dz/151020_0002.png
This is the code how I do it now:
case FB_ID:
FacebookSdk.sdkInitialize(getApplicationContext());
fbCallbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
LoginManager.getInstance().registerCallback(fbCallbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "FB");
openFragment(MakeWallPostFragment.newInstance(social_id,null), false);
// App code
}
#Override
public void onCancel() {
// App code
finish();
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
break;
This code give me this kind of error:
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions")); //this is the culprit string gives me:
The publish_actions permissions are missing,
the share will fail unless this app was authorized to publish in another installation. this error
What should I use to make it happen?
Btw, this is the video with explanation, but I think all this stuff is deprecated now:http://www.youtube.com/watch?v=iBBVkwBeaY4
I am able to access the id, firstname, lastname, gender, and email of a GraphUser by using the following code.
But, I also need access to "location", "number of friends", "basic info" and "work company". How can this be done? I have tried other stackoverflow links, and checked the Facebook SDK link, but not getting a break through. Could I be provided code to directly access the required fields in the same way as the data that I already have?
What other permissions would I need?
loginBtn.setReadPermissions(Arrays.asList("public_profile", "email", "user_friends", "user_birthday", "read_friendlists"));
loginBtn.setUserInfoChangedCallback(new UserInfoChangedCallback() {
#Override
public void onUserInfoFetched(GraphUser user) {
if (user != null) {
login_text.setText("Please login to continue");
userDetails = new JSONObject();
try {
Log.d("user birthday", user.getBirthday());
userDetails.put("fbId", user.getId());
userDetails.put("firstName", user.getFirstName());
userDetails.put("lastName", user.getLastName());
userDetails.put("gender", user.getProperty("gender").toString());
userDetails.put("email", user.getProperty("email").toString());
} catch (JSONException e) {
Log.d("Error: ", "Error setting user settings in FBActivity");
}
} else {
//login_text.setText("You are not logged");
}
}
});
EDIT:
I got everything except the total number of friends an individual has. How can that be done. I have gone through your links and it seems that I need to call another GraphRequest link. But I don't that. I want the total number of friends (no names, no details, just the number). I have added the permission "user_friends". What code should I write to get the number?
This is a pretty straightforward answer and the facebook documentation covers these details. https://developers.facebook.com/docs/reference/android/current .
https://developers.facebook.com/docs/graph-api
Here is the answer anyway!
You will need user_friends for the number of friends. It returns the total count of friends.
The default permission set called "basic info" has been removed, and replaced by "public profile".
user_location for location.
user_work_history for the work company.
please note : users can choose to not give these permissions to your app, in which case you should handle those scenarios properly, else your app will get rejected in the review process.
To get number of friends please refer to the following link:
https://developers.facebook.com/docs/graph-api/reference/v2.4/user/friends
Permissions needed would be: user_friends, which you already have included..
You'll get friends count in field 'summary' in the name of total_count
Similar question: facebook api on android - how can I get the number of friends that a user has?
loginBtn.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
new GraphRequest(
loginResult.getAccessToken(),
"/me/friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.i("response", response.getJSONArray().toString()); //find the summary 'total_count' in the response
}
}
).executeAsync();
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException exception) {
}
});
I'm having a problem revoking Facebook permissions using the Android SDK.
There's a case in my app where I want to revoke all permissions. According to the Facebook documentation, you can use AsyncFacebookRunner to do this, and "if you don't specify a permission then this will de-authorize the application completely."
I'm currently doing it like this:
String method = "DELETE";
Bundle params = new Bundle();
params.putString("permission", "");
mAsyncRunner.request("/me/permissions", params, method, new RequestListener()
{ ... }, null);
using the request signature like this:
void request(String graphPath, Bundle parameters, final String httpMethod,
RequestListener listener, final Object state)
The onComplete() callback function seems to come back OK, but doesn't appear to have de-authorized the access token. I'm inferring this because the next time I call facebook.authorize(), it works without pushing the user to the Facebook login page.
Any ideas what I need to change to completely de-authorize an access token? Or is there a different/better way to do this? Many thanks!
For anybody looking to do this in later versions of the SDK/Graph API - It appears the correct way to do this now is as shown here https://developers.facebook.com/docs/graph-api/reference/user/permissions/
new Request(
session,
"/me/permissions/{permission-to-revoke}",
null,
HttpMethod.DELETE,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
Leaving the /{permission-to-revoke} off of the second parameter will revoke all the permissions
You can delete the entire application (not only permissions) from users Facebook account using latest SDK (mine is 4.1.1)
void deleteFacebookApplication(){
new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions", null, HttpMethod.DELETE, new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
boolean isSuccess = false;
try {
isSuccess = response.getJSONObject().getBoolean("success");
} catch (JSONException e) {
e.printStackTrace();
}
if (isSuccess && response.getError()==null){
// Application deleted from Facebook account
}
}
}).executeAsync();
}
It appears from this post: Facebook deauthorize my app and others that it's not possible to deauthorize an application programmatically. Unfortunately, the call above returns successfully to onCreate() but does nothing to deauth/delete the app for the user.
Bottom line: It looks like the only way to deauth an app is for the user to do it directly in Facebook. If anyone knows differently, please say so - but otherwise, don't waste your time trying! Thanks.
I am using the code suggested in the question and it completely de-authorized my test application. Tested it several times and it worked every each one of them.
This is also the code suggested in the official facebook documentation here: https://developers.facebook.com/docs/mobile/android/build/ - Step 7
I managed to login to Facebook / get permissions.. retrieve friends data, names/ids etc.
The issue is that I cannot send an app invite to my friends. I'd like to send the invite without a dialog to a single person. But it seems that's wishful thinking. Now I'd settle for anything. It seems nothing will do the job!
I tried the dialog provided by Facebook Graph API but it tells me that the display is not supported (error 103). Also tried the fix modifying the url inside the Facebook SDK to not point to the mobile version and set the display as popup. Still no good (same error);
Any thoughts on this?
Thank you in advance.
(BTW, it seems to me like Facebook is a very unreliable service!)
This code will bring up an app invite dialog (and I don't know how to send an invite without a dialog). Note: assumes that facebook has been successfully authorized/logged in:
Facebook facebook = new Facebook( MY_APP_ID );
...
Bundle parameters = new Bundle();
parameters.putString( "message", "Check this out!" );
facebook.dialog( activity, "apprequests", parameters,
new Facebook.DialogListener()
{
public void onComplete() { ... }
public void onFacebookError( FacebookError e ) { ... }
public void onError(DialogError e) { ... }
public void onCancel() { ... }
} );