我正在尝试将Facebook整合到我的游戏中以在用户的墙上发布记录但是在登录后我得到一个授予权限的窗口,当我接受时,我希望我的游戏能够在不做任何其他事情的情况下再次恢复。
我有一个变量(useFacebook
),当会话启动时或者会话已经开始时应该变为true
。但是,它的行为总是false
。如果我手动将其转为true
,我会在Facebook上收到错误。
这是相关代码:
@Override
public void onResumeGame() {
super.onResumeGame();
if (mServ != null)
{
mServ.resumeMusic();
}
checkFaceBook();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
public void checkFaceBook()
{
Session.openActiveSession(this, false, new Session.StatusCallback()
{
@Override
public void call(Session session, SessionState state, Exception exception)
{
if (session.isOpened())
{
// Never enters here.
Request.executeMeRequestAsync(session, new Request.GraphUserCallback()
{
@Override
public void onCompleted(GraphUser user, Response response)
{
if (user != null)
{
fbUsername = user.getFirstName();
useFacebook = true;
}
}
});
}
}
});
}
public void facebookLogin()
{
Session.openActiveSession(this, true, new Session.StatusCallback()
{
@Override
public void call(Session session, SessionState state, Exception exception)
{
if (session.isOpened())
{
// Never enters here.
Request.executeMeRequestAsync(session, new Request.GraphUserCallback()
{
@Override
public void onCompleted(GraphUser user, Response response)
{
if (user != null)
{
// CALLBACK: USER IS LOGGED IN
// DO YOUR STUFF HERE
fbUsername = user.getFirstName();
useFacebook = true;
facebookFeedDialog("Test");
}
}
});
}
}
});
}
public void facebookFeedDialog(String message)
{
Bundle params = new Bundle();
params.putString("name", message);
params.putString("caption", "ccccc");
params.putString("description", "ddddd");
params.putString("link", "https://market.android.com/details?id="+this.getApplication().getPackageName().toString());
params.putString("picture", "http://www.myimage.com/01.jpg");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(), params)).setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error)
{
if (error == null)
{
final String postId = values.getString("post_id");
if (postId != null)
{
// POSTED
}
else
{
// POST CANCELLED
}
}
else if (error instanceof FacebookOperationCanceledException)
{
// POST CANCELLED
}
else
{
// ERROR POSTING
}
}
}).build();
feedDialog.show();
}
public boolean onSceneTouchEvent(Scene pScene,
TouchEvent pSceneTouchEvent) {
if (mFB.onAreaTouched(pSceneTouchEvent, pSceneTouchEvent.getX(), pSceneTouchEvent.getY()))
{
mClickSnd.play();
if (useFacebook == true)
{
facebookFeedDialog("Test");
}
else
{
facebookLogin();
}
return true;
}
return false;
}
这些是我得到的屏幕:
感谢。
答案 0 :(得分:0)
屏幕正确,用户需要在允许读取或发布任何数据之前授权您的应用。
在你的onResume中思考你应该尝试使用Session.getActiveSession();这将使您获得当前的活动会话。