我正在整理一个显示Facebook PlacePicker的简单Android活动。当用户从列表中选择一个地点时,它应该将他们的选择发布到他们的墙上。这不应该需要登录按钮;
,该应用不会请求权限(在这种情况下为publish_actions
)。
我的PlacePicker工作正常。我期望的所有地方都被加载,选择一个会触发相应的功能,但requestNewPublishPermissions()
呼叫每次都会失败。抛出的异常是:
com.facebook.FacebookAuthorizationException:用户以不同的Facebook用户身份登录。
我只能在网上找到其他2个包含此错误消息的讨论,但它们都没有对我有任何帮助。我已经退出Facebook应用程序,在我的移动浏览器上退出Facebook,但仍然会引发相同的异常。
这到底是怎么回事?
的onCreate()
Log.d(TAG, "CheckIn: onCreate");
super.onCreate(savedInstanceState);
isShared = false;
setContentView(R.layout.activity_checkin);
initLocationManager();
initPlacePickerFragment(getSupportFragmentManager());
lifecycleHelper = new UiLifecycleHelper(this, statusCallback);
lifecycleHelper.onCreate(savedInstanceState);
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
Session session = Session.getActiveSession();
if (session == null) {
Log.d(TAG, "CheckIn: null session");
if (savedInstanceState != null) {
session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
}
if (session == null) {
session = new Session(this);
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
}
}
if (savedInstanceState != null) {
pendingPublishReauthorization = savedInstanceState.getBoolean(PENDING_PUBLISH_KEY, false);
}
发布()
Log.d(TAG,"CheckIn: Publishing Check In");
Session session = Session.getActiveSession();
if (session != null){
// Check for publish permissions
List<String> permissions = session.getPermissions();
for (String s : permissions) {
Log.d(TAG, "CheckIn: permission: " + s);
}
if (!isSubsetOf(PERMISSIONS, permissions)) { // This is always false, and loops endlessly
Log.d(TAG, "CheckIn: Getting permissions");
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
newPermissionsRequest.setCallback(new StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
Log.d(TAG, "CheckIn: newPermissionsRequest.call()");
Log.d(TAG, "CheckIn: " + state.toString());
Log.e(TAG, "CheckIn: " + exception.toString());
}
});
session.requestNewPublishPermissions(newPermissionsRequest);
return;
} else {
Log.d(TAG, "CheckIn: Has permissions");
}
// Activity has never gotten this far
Bundle postParams = new Bundle();
postParams.putString("name", "Some");
postParams.putString("caption", "Update Caption");
postParams.putString("description", "Checked in somewhere who cares");
postParams.putString("link", "http://www.redrobin.com/");
Request.Callback callback= new Request.Callback() {
public void onCompleted(Response response) {
Log.d(TAG, "CheckIn: All set!");
isShared = false;
CheckInActivity.this.isShared = false;
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString("id");
} catch (JSONException e) {
Log.i(TAG, "CheckIn: JSON error " + e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(CheckInActivity.this, error.getErrorMessage(), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(CheckInActivity.this, postId, Toast.LENGTH_LONG).show();
}
}
};
Log.d(TAG, "CheckIn: Making me/feed request");
Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
输出:
CheckIn:onCreate
CheckIn:initLocationManager
CheckIn:initPlacePickerFragment
CheckIn:onResume
CheckIn:会话状态已更改:已打开
CheckIn:找到新位置
CheckIn:setupPickPlaceFragment
CheckIn:找到的地方//选择了一个地方
CheckIn:doPostStory
CheckIn:会话是打开还是关闭。分享
CheckIn:会话状态已更改:已关闭 CheckIn:会话状态已更改:已打开
CheckIn:发布签到
CheckIn:获取权限
CheckIn:onPause
CheckIn:onSaveInstanceState
CheckIn:onActivityResult
CheckIn:onResume
CheckIn:newPermissionsRequest.call()
CheckIn:OPENED
CheckIn:com.facebook.FacebookAuthorizationException:用户以不同的Facebook用户身份登录 此时输出开始无休止地重复来自&#34; newPermissionsRequest.call()&#34;或&#34;会话状态已更改:已打开。发布签到。&#34;
我不想用代码重载这篇文章,但如果还有其他任何有用的功能,请告诉我。