2
我正在使用Facebook的Android SDK 3.0。我想要的是用戶的ID和訪問令牌,我越來越完美。問題是如果fb應用程序沒有安裝在設備上,我試圖登錄,它會登錄,但登錄對話框彈出再次,即使點擊關閉按鈕的對話框不斷彈出,直到除非我再次登錄。Facebook的Android SDK登錄對話框
這裏是我的代碼:
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;
}
嘿@ 5agado我試圖實現與UILifeCycleHelper並在某些情況下,'data' PARAM的FB登錄流程它通常有一個包含FB響應的字段'mMap',爲空。爲什麼會發生這種情況? – toobsco42 2013-08-26 07:17:19