在我们的应用程序中,我们将 Facebook 与新的 Facebook sdk 3.0 版集成。
如果我从 eclipse 在我的测试设备上启动应用程序,一切正常。facebook 应用程序(如果未安装本机应用程序,则为 webView)打开,登录到 Facebook 回调并发布帖子。
但是,如果我将此代码作为 google playstore 中的 apk 发布,从那里下载并测试它,facebook 应用程序将启动,用户登录并允许发布,然后什么都没有发生,没有帖子到墙上 O_o。
这是代码:
private void facebookLogin()
{
Session.openActiveSession(this, true, new Session.StatusCallback()
{
@Override
public void call(Session session, SessionState state, Exception exception)
{
// TODO Auto-generated method stub
if(session.isOpened())
{
performPublish(PendingAction.POST_PHOTO);
}
}
});
}
private void performPublish(PendingAction action) {
Session session = Session.getActiveSession();
if (session != null) {
pendingAction = action;
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.
session.requestNewPublishPermissions(new Session.NewPermissionsRequest(this, PERMISSIONS));
}
}
}
private void handlePendingAction()
{
PendingAction previouslyPendingAction = pendingAction;
// These actions may re-set pendingAction if they are still pending, but we assume they
// will succeed.
pendingAction = PendingAction.NONE;
switch (previouslyPendingAction)
{
case POST_PHOTO:
postPhoto();
break;
case POST_STATUS_UPDATE:
postStatusUpdate();
break;
}
}
private void postPhoto()
{
if (hasPublishPermission())
{
Bitmap logo = g.getLevelBitmaps()[0];
Request request = Request.newUploadPhotoRequest(Session.getActiveSession(), logo, new Request.Callback()
{
@Override
public void onCompleted(Response response)
{
postStatusUpdate();
if(g.isAchievementsActivated())
{
Swarm.init(logoQuestion,3777,"831e03485c37444f9b94de8fdf2e676f");
SwarmAchievement.unlock(10093);
}
//Toast.makeText(logoQuestion, "Posted", Toast.LENGTH_SHORT).show();
performPublish(PendingAction.POST_STATUS_UPDATE);
}
});
Bundle params = new Bundle();
params.putString("description", "Who know's that logo? \n" + hintQuestionText+ " posted from Videogames Logoquiz now available for Android and iOS");
//request.setParameters(params);
request.executeAsync();
}
else
{
pendingAction = PendingAction.POST_PHOTO;
}
}
private void postStatusUpdate()
{
if (hasPublishPermission())
{
String question = "Who know's that logo? "+hintQuestionText+" Get Videogames Logoquiz. It's now available for iOS and Android.";
Request request = Request
.newStatusUpdateRequest(Session.getActiveSession(), question, new Request.Callback()
{
@Override
public void onCompleted(Response response)
{
Toast.makeText(logoQuestion, "Posted", Toast.LENGTH_SHORT).show();
}
});
request.executeAsync();
}
else
{
pendingAction = PendingAction.POST_STATUS_UPDATE;
}
}
hasPublishPermission 函数:
private boolean hasPublishPermission()
{
Session session = Session.getActiveSession();
return session != null && session.getPermissions().contains("publish_actions");
}
我要求的权限是:
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions","user_photos");
在我的 Android 清单中,我有以下权限来集成 facebook:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
我不明白为什么它可以通过测试工作,但不能在相同的发行版本上工作。
有人知道有解决办法吗?
谢谢你们!