I am using the Facebook SDK but I want to create the photo album but I am getting ACCESS_TOKEN_REMOVED in the session.
Getting this in session
{Session state:OPENED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[read_stream, manage_friendlists, read_mailbox, status_update, photo_upload, video_upload, sms, create_event, rsvp_event, email, xmpp_login, create_note, share_item, publish_stream, ads_management, read_insights, read_requests, manage_notifications, read_friendlists, manage_pages, publish_actions, user_birthday, user_religion_politics, user_relationships, user_relationship_details, user_hometown, user_location, user_likes, user_activities, user_interests, user_education_history, user_work_history, user_online_presence, user_website, user_groups, user_events, user_photos, user_videos, user_photo_video_tags, user_notes, user_checkins, user_about_me, user_status, basic_info]}, appId:458921577539675}
Code.
/**
* Connect to facebook using Facebook SDK.
*/
public void connectToFacebook() {
Session session = Session.getActiveSession();
if(session == null || session.isClosed()) {
Session.openActiveSession((Activity)context, true, new StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
if(session.isOpened() && state == SessionState.CREATED_TOKEN_LOADED) {
Log.v(GlobalVars.TAG, "Token::" + session.getAccessToken());
Request.executeMeRequestAsync(session, new GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
if(response != null) {
Log.v(GlobalVars.TAG, "Response::" + response);
Log.v(GlobalVars.TAG, "Response::" + user.getFirstName() + ":::" + user.getLastName());
}
}
});
}
}
});
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
If you are just seeing ACCESS_TOKEN_REMOVED in your log, make sure you are printing session.getAccessToken().getToken(). In the example above, replace
Log.v(GlobalVars.TAG, "Token::" + session.getAccessToken());
with
Log.v(GlobalVars.TAG, "Token::" + session.getAccessToken().getToken());
Same problem that i was facing from last 2 days and finally i get to know this. Facebook SDK will not log access tokens to logcat (to avoid leaking user tokens via the log as said in decsription).
Just add these lines after FacebookSdk.sdkInitialize(), i would recomend you do this only in debug mode:
if (BuildConfig.DEBUG) {
FacebookSdk.setIsDebugEnabled(true);
FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
}
You have to enable facebook sign in on Firebase Console and add the facebook app id and app secret key and it should work fine
I took the same problem :/
You can check:
Is appId correct?
Was keyhash registered in facebook app center?
Does app namespace / package name match with your manifest file? ( on facebook app center )
Is application live?
If everything is right I really don't know how to help you...
I checked all items that Fernando said and add it
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
I don't know if this last line was what solved the problem or if it's something random.
I'm using Facebook Android SDK 3.17 for Xamarin
Greetings from Argentina
Hernan
www.hernanzaldivar.com
Related
This code results in the onCompleted method being called on Samsung JELLYBEAN but not on Motorola KITKAT or LG LOLLIPOP devices. The log returns: W/Facebook test(20699): Facebook session status changed - OPENED - Exception: null on all devices.
private class SessionStatusCallback implements Session.StatusCallback {
#Override
public void call(Session session, SessionState state, Exception exception) {
String message = "Facebook session status changed - "
+ session.getState() + " - Exception: " + exception;
Log.w("Facebook test", message);
if (session.isOpened()) {
Request.newMeRequest(session, new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
Log.d("onCompleted","");
}
}).executeAsync();
}
}
}
I have checked permissions and the hashes stored. This is my onActivityResult method:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
UPDATE: I created a test project with identical code to the problem app. This project doesn't have the problem, which suggests it isn't a java issue. The manifests are the same with regards to Facebook. I have the correct app_id in each case. The settings of the apps on developers.facebook.com are the same except for package name, class name and key hash.
Go to developers.facebook.com
Select your app
Select Status and Review
Change "Do you want to make this app and all its live features
available to the general public?" to NO
(I waited about ten minutes at this point, which may not be necessary)
Then change the same setting back to YES
I am using the Facebook SDK for an Android app which requires 2 permissions additional to the standard one for logging in/out.
The two permissions are a read permission: User Groups and a publish permissions: publish.
The problem is that in the latest facebook api requires to ask each permission separately. Which I am fine with.
The issue is that the session object is not updated with the new permissions after the user confirms them, unless I logout and login into the app again.
This would not be an issue if I could ask all permissions at once, but again, not possible anymore.
Is there any other way to avoid this?
And yes, I have tried everything in the OnActivityResult, and the permissions in the Session.getActiveSession() object is not updated with the new permissions, even though if I try to do the needed action it works.
And it's totally unfeasable to ask the user to logout and login of the app after each permission request.
This is what I have in my OnActivityResult (which works completely fine btw).
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("RADARE","ON ACTIVITY RESULT CALLED");
Log.d("RADARE","REQUEST CODE: " + requestCode + " == RESULT CODE: " + resultCode + " == INTENT: " + data.toString());
if (RESULT_CANCELED == resultCode) {
Log.d("RADARE", "Canceled");
}
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
#Override
public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
Log.e("Activity", String.format("Error: %s", error.toString()));
}
#Override
public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
Log.i("Activity", "Success!");
}
});
Session session = Session.getActiveSession();
Log.d("RADARE","Session info: TOKEN: " + session.getAccessToken() + " == PERMISSIONS: " + session.getPermissions().toString() + " == STATE: " + session.getState());
Toast.makeText(this, "You have to logout and login again in order for the service to work.", Toast.LENGTH_LONG).show();
My first idea would be instead of using Session.getPermissions().contains("needed_permission_here") to actually check online for the permission instead of the Session object.
Right now it just enters a loop:
The permissions are checked => permissions is not there => Jumps to facebook app asking for permissions => the user grants it => the app checks again for permission (which are not there even though the user has confirmed them) and jumps to facebook (which of course just replies back with the confirmed permission) and they dance back and forth infinitely.
Do you have any other ideas than checking the permissions online instead of the object?
Quoting from FB Login Permissions page
user_groups- Limited Use
This permission is granted to apps building a Facebook-branded client on platforms where Facebook is not already available. For example, Android and iOS apps will not be approved for this permission. In addition, Web, Desktop and TV apps will not be granted this permission
And for checking if the permissions are granted already
private static final String PERMISSION = "publish_actions";
<- Whatever read permissions you need ->
authButton.setReadPermissions(Arrays.asList("email", "user_birthday",
"read_stream", "user_friends","read_friendlists "));
public void call(Session session, SessionState state,
Exception exception) {
if (session.isOpened()) {
List<String> permissions = session.getPermissions();
if (!permissions.contains(PERMISSION)) {
pendingAnnounce = true;
requestPublishPermissions(session);
return;
}
}
I dont know how much of help this will be to you..
I want to implement Facebook Login in my application, but here I am getting problem while trying to login i.e :
**{Session state:OPENING, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[]}, appId:1xxxxxxxxxxxxxxx}**
and sometimes this one also:
**{Session state:CLOSED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[]}, appId:1xxxxxxxxxxxxxxx}**
Note: The above problem occurs when my device already has installed NATIVE FACEBOOK APP, if I uninstall the Facebook app it works absolutely fine. Can Anyone please help me out what the matter is ?
Thanks in advance
Be sure to override in your Activity the onActivityResult method:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
Try
AccessToken.getCurrentAccessToken().getToken();
instead of using the toString() function.
I know this is an old ticket, but no one has appeared to give the correct answer. The token is removed from toString to prevent token exposure.
com.facebook.LoggingBehavior (from line 29):
/**
* Indicates that access tokens should be logged as part of the request logging; normally they are not.
*/
INCLUDE_ACCESS_TOKENS,
com.facebook.AccessToken (from line 322):
private String tokenToString() {
if (this.token == null) {
return "null";
} else if (Settings.isLoggingBehaviorEnabled(LoggingBehavior.INCLUDE_ACCESS_TOKENS)) {
return this.token;
} else {
return "ACCESS_TOKEN_REMOVED";
}
}
To show the token in toString requests simply add logging to the settings :
Settings.addLoggingBehavior( LoggingBehavior.INCLUDE_ACCESS_TOKENS );
this.mUiLifecycleHelper = new UiLifecycleHelper( this, this.mCallback );
this.mUiLifecycleHelper.onCreate( savedInstanceState );
Hope this helps others with the same issue.
Just a heads up.
This exact case was happening to me. My login stopped working just because I changed my Activity launch mode in Manifest.xml file from:
android:launchMode="singleInstance"
to
android:launchMode="singleTask"
So, I changed it again to singleInstance and it is working fine now.
This maybe happening because you didn't add the hashkey in your Facebook app. Check out this link Generating Hashkey for Android to learn how to generate hashkey.
This was happening to me too. It started working after i added the hashkey in Facebook app.
This is my working integration of new Facebook SDK 4.1.
First you need to init SDKin 4.1 ///
/** if face book SDK is not initialized then initialized.*/
if(!FacebookSdk.isInitialized())
FacebookSdk.sdkInitialize(BaseActivity.this);
Now you need callback manger
/** create face book callback factory.*/
if(null == callbackManager)
callbackManager = CallbackManager.Factory.create();
These are call back.
public final FacebookCallback<LoginResult> _mcallbackLogin = new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
if(loginResult.getAccessToken() != null){
Log.i("TAG", "LoginButton FacebookCallback onSuccess token : "+ loginResult.getAccessToken().getToken());
GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
if(null != object){
Log.e("TAG", object.optString("name"),object.optString("first_name"),object.optString("email"),false).execute();
}
}
}).executeAsync();
}
}
#Override
public void onCancel() {
Log.e("TAG", "LoginButton FacebookCallback onCancel");
}
#Override
public void onError(FacebookException exception) {
Log.e("TAG","Exception:: "+exception.getStackTrace());
}
};
Now you need register call back on facebook login button
loginBtn.registerCallback(BaseActivity.callbackManager,_mcallbackLogin);
I followed the step of "Create a new Android Project with Facebook Login" section at https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/ The login process is fine. Because I would like to use the native Android button for a user to log in, I modify the code slightly by moving the following code into a View.OnClickListener() of a native Android button. The following is the code in the listener:
Session.openActiveSession(MainActivity.this, true, new Session.StatusCallback() {
// callback when session changes state
#Override
public void call(Session session,SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session,new Request.GraphUserCallback() {
// callback after Graph API
// response with user object
#Override
public void onCompleted(GraphUser user,Response response) {
if (user != null) {
Toast.makeText(getApplicationContext(), "Hello " + user.getName() +" "+user.getId()+"!", Toast.LENGTH_LONG).show();
}
}
});
}
}
});
The onActivityResult() and AndroidManifest.xml is the same as the tutorial
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
However, I would like to request get "read_friendlists" when a user logs in successfully. I read the tutorial at https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/ but it uses Facebook SDK customized button. How can I achieve the same behavior with a native Android button like my code shown above?
I just answered a similar question on another post. My solution allows you to use a native button and request additional read permissions when the user first logs in. Check it out here Ask for more permissions with 3.0 SDK
So I have a simple login button that does this in my oncreate:
mLoginButton = (LoginButton)findViewById(R.id.connect_facebook_button);
mLoginButton.setApplicationId(.getResources().getString(R.string.app_id));
mLoginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
public void onUserInfoFetched(GraphUser user) {
setUser(user); // Just sets mUser to be this user
try {
Toast.makeText(this, mUser.getFirstName(), Toast.LENGTH_SHORT).show();
} catch (Exception FacebookException) {
FacebookException.printStackTrace();
}
}
});
All of that is called successfully, including the onUserInfoFetched.
The problem is, in every instance, my Graphuser user is null.
My appID is correct, my android hash is the debug one that they give me (tested on sample apps worked fine), the login screen does actually pop up... Not really sure where to go from here.
Also, if I hit the button twice, I get an error:
an attempt was made to open a session that has a pending request
Whoops! Forgot my activity result!
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
That did the trick.