我正在尝试将 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;
}
这些是我得到的屏幕:
谢谢。