我正在使用 Facebook android sdk 3.0。我想要的是我得到完美的用户 ID 和访问令牌。问题是,如果设备上未安装 fb 应用程序并且我尝试登录,它确实登录但登录对话框再次弹出,即使在单击该对话框对话框的关闭按钮后仍然弹出,直到并且除非我再次登录。
这是我的代码:
if(v.getId()==imgLike.getId())
{
try
{
/*
* Logging in with Facebook
*/
try
{
login_facebook();
}catch(NullPointerException npx)
{
npx.printStackTrace();
}
catch(Exception ex)
{
}
}catch(Exception ex)
{
ex.printStackTrace();
}
}
public void login_facebook()
{
try
{
Session.openActiveSession(acontext, true, new Session.StatusCallback() {
@Override
public void call(final Session session, SessionState state, Exception exception) {
// TODO Auto-generated method stub
if(session.isOpened())
{
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(acontext, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
}
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
// TODO Auto-generated method stub
if(user!=null)
{
fbUserid=user.getId();
fbAccessToken=session.getAccessToken();
Log.i("User Name ", "Name : "+user.getName());
Log.i("User Id ", "Id : "+user.getId());
Log.i("User Access Token ", "Access Token : "+session.getAccessToken());
new LikeUrl().execute(carName.get(currentIMage));
}
}
});
}
}
});
}catch(NullPointerException npx)
{
npx.printStackTrace();
}catch(BadTokenException bdx)
{
bdx.printStackTrace();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try
{
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}catch(IllegalStateException ilgx)
{
ilgx.printStackTrace();
}
catch (NullPointerException e) {
// TODO: handle exception
e.printStackTrace();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
for (String string : subset) {
if (!superset.contains(string)) {
return false;
}
}
return true;
}