Android - Facebook SDK 登录
Posted
技术标签:
【中文标题】Android - Facebook SDK 登录【英文标题】:Android - Facebook SDK login 【发布时间】:2016-02-09 18:58:31 【问题描述】:我尝试登录,第一次弹出Facebook确认页面,然后我点击同意,然后回到相同的登录页面,但按钮没有变为注销,我再次点击,它显示加载图标 1 秒,然后什么也没发生,Facebook 确认页面没有弹出,谁能帮忙,谢谢!
public class FacebookLogin extends Activity
CallbackManager callbackManager;
private AccessToken accessToken;
@Override
protected void onCreate(Bundle savedInstanceState)
FacebookSdk.sdkInitialize(getApplicationContext());
super.onCreate(savedInstanceState);
setContentView(R.layout.facebooklogin);
callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.FaceBooklogin_button);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>()
@Override
public void onSuccess(LoginResult loginResult)
accessToken = loginResult.getAccessToken();
Log.d("FB","access token got.");
Toast.makeText(FacebookLogin.this,"Gooooooooood",Toast.LENGTH_LONG).show();
GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback()
@Override
public void onCompleted(JSONObject object, GraphResponse response)
Log.d("FB","complete");
Log.d("FB",object.optString("name"));
Log.d("FB",object.optString("link"));
Log.d("FB",object.optString("id"));
);
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link");
request.setParameters(parameters);
request.executeAsync();
@Override
public void onCancel()
Log.d("FB","CANCEL");
Toast.makeText(FacebookLogin.this,"CANCLE",Toast.LENGTH_LONG).show();
@Override
public void onError(FacebookException error)
Toast.makeText(FacebookLogin.this,"Error",Toast.LENGTH_LONG).show();
);
这是我点击登录时的日志
02-10 02:55:44.141 23262-23262/com.addtw.aweino1 I/Timeline: Timeline: Activity_launch_request id:com.addtw.aweino1 time:61774128
02-10 02:55:44.171 23262-23262/com.addtw.aweino1 W/ResourcesManager: getTopLevelResources: com.addtw.aweino1 for user 0
02-10 02:55:44.171 23262-23262/com.addtw.aweino1 D/PhoneWindow: *FMB* installDecor mIsFloating : false
02-10 02:55:44.171 23262-23262/com.addtw.aweino1 D/PhoneWindow: *FMB* installDecor flags : 8454400
02-10 02:55:44.181 23262-23262/com.addtw.aweino1 D/Activity: performCreate Call Injection manager
02-10 02:55:44.181 23262-23262/com.addtw.aweino1 I/InjectionManager: dispatchOnViewCreated > Target : com.facebook.FacebookActivity isFragment :false
02-10 02:55:44.191 23262-23262/com.addtw.aweino1 D/DisplayManager: DisplayManager()
02-10 02:55:44.201 23262-23262/com.addtw.aweino1 D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
02-10 02:55:44.201 23262-23262/com.addtw.aweino1 D/PhoneWindow: *FMB* isFloatingMenuEnabled return false
02-10 02:55:44.221 23262-23289/com.addtw.aweino1 D/mali_winsys: new_window_surface returns 0x3000, [720x1280]-format:1
02-10 02:55:44.241 23262-23262/com.addtw.aweino1 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@2ff6ae77 time:61774222
02-10 02:55:44.481 23262-23419/com.addtw.aweino1 I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
02-10 02:55:44.741 23262-23262/com.addtw.aweino1 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@35311897 time:61774726
02-10 02:55:50.701 23262-23412/com.addtw.aweino1 I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
【问题讨论】:
【参考方案1】:我明白了! 需要更多的东西
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
@Override
protected void onResume()
super.onResume();
AppEventsLogger.activateApp(this);
@Override
protected void onPause()
super.onPause();
AppEventsLogger.deactivateApp(this);
【讨论】:
以上是关于Android - Facebook SDK 登录的主要内容,如果未能解决你的问题,请参考以下文章
通过 Xamarin.Facebook.Android sdk 登录 Facebook
Android上的Unity Facebook SDK登录错误