Facebook活动未正确载入Facebook-sdk 4.4.0 [英] Facebook Activity not loading correctly in facebook-sdk 4.4.0
问题描述
FacebookSdk.sdkInitialize(getApplicationContext());
callbackmanager = CallbackManager.Factory.create();
//设置权限
LoginManager.getInstance()。logInWithReadPermissions((Activity)getContext(),Arrays.asList(email,public_profile));
LoginManager.getInstance()。registerCallback(callbackmanager,
new FacebookCallback< LoginResult>(){
@Override
public void onSuccess(LoginResult loginResult){
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback(){
@Override
public void onCompleted(JSONObject userInfo ,GraphResponse graphResponse){
try {
FacebookClientController.setUserId(userInfo.optString(ID));
FacebookClientController.setDisplayName(userInfo.optString(NAME));
FacebookClientController.setEmailAddress (userInfo.optString(EMAIL));
JSONObject pi cJson = userInfo.getJSONObject(PICTURE).getJSONObject(data);
FacebookClientController.setProfilePicUrl(picJson.optString(url));
Log.d(LOGTAG,\\\
Username:+ FacebookClientController.getDisplayName());
Log.d(LOGTAG,\\\
Email:+ FacebookClientController.getEmailAddress());
Log.d(LOGTAG,\UserId:+ FacebookClientController.getUserId());
Log.d(LOGTAG,\ProfilePicUrl:+ FacebookClientController.getProfilePicUrl());
} catch(JSONException e){
Log.d(LOGTAG,Json Error);
}
}
}
);
Bundle parameters = new Bundle();
parameters.putString(FIELDS,FB_REQUEST_FIELDS);
request.setParameters(parameters);
GraphRequest.executeBatchAsync(request);
Toast.makeText(getContext(),登录成功+ loginResult.toString(),Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel(){
Log.d(LOGTAG,On cancel);
}
@Override
public void onError(FacebookException error){
Log.d(LOGTAG,error.toString());
}
});
}
我在我的应用程序中获得了左边的屏幕,而不是右边屏幕应该运行上面的代码。有谁能告诉我哪里可以问题?
Logcat:
---------开始/ dev / log / main
I / AppHost.Android(10873):注册监听器处理
onActivityResult:com.example.office.docsui.common.SignInController $ 5
--------- / dev / log / system的开始
I / ActivityManager(449):START u0 {act = NATIVE_WITH_FALLBACK
cmp = com.example.office.powerworld / com.facebook.FacebookActivity(has
extras)} from pid 10873
I / TelemetryLifeCycleState (10873):活动暂停开始。
活动:1099625720,PPTActivity,AppState = 3
I / ActivityManager(449):START u0 {act = NATIVE_WITH_FALLBACK
cmp = com.example pont 10873
I / TelemetryLifeCycleState(10873):活动暂停结束。
活动:1099625720,PPTActivity,AppState = 2
I / TelemetryLifeCycleState(10873):创建活动。
活动:1107534680,com.facebook.FacebookActivity
I / AppHost.Android(10873):onActivityStarted,
foregroundActivityCount = 1,mEventsEnabled = true ,mResumeEnabled = false
I / AppHost.Android(10873):这不是办公室
activity :: com.facebook.FacebookActivity
I / TelemetryLifeCycleState(10873):活动恢复开始。
活动:1107534680,com.facebook.FacebookActivity,AppState = 2
I / TelemetryLifeCycleState(10873):活动恢复结束。
活动:1107534680,com.facebook.FacebookActivity,AppState = 3,
suspendedTime = 54215
I / TelemetryLifeCycleState(10873):活动暂停开始。
活动:1107534680,com.facebook.FacebookActivity,AppState = 3
I / TelemetryLifeCycleState(10873):活动暂停结束。
活动:1107534680,com.facebook.FacebookActivity,AppState = 2
I / TelemetryLifeCycleState(10873):创建活动。
活动:1107673504,com.facebook.FacebookActivity
D / dalvikvm(10873):GC_FOR_ALLOC释放2064K,20%免费8974K / 11096K,
暂停27ms,共30ms
I / AppHost.Android(10873):onActivityStarted,
foregroundActivityCount = 1,mEventsEnabled = true,mResumeEnabled = false
I / AppHost.Android(10873):这不是办公室
activity :: com.facebook.FacebookActivity
I / TelemetryLifeCycleState(10873):活动恢复开始。
活动:1107673504,com.facebook.FacebookActivity,AppState = 2
I / TelemetryLifeCycleState(10873):活动恢复结束。
活动:1107673504,com.facebook.FacebookActivity,AppState = 3,
suspendedTime = 54303
D / mali_winsys(10873):new_window_surface返回0x3000
D / mali_winsys(10873):new_window_surface返回0x3000
D / mali_winsys(10873):new_window_surface返回0x3000
D / mali_winsys(10873):new_window_surface返回0x3000
I / Keyboard.Facilitator(614):onFinishInput ()
I / ActivityManager(449):显示
com.example.office.powerworld / com.facebook.FacebookActivity:+ 346ms
I / ActivityManager(449):显示
com.example.office.powerworld / com.facebook.FacebookActivity:+ 346ms
D / mali_winsys(10873):new_window_surface返回0x3000
D / mali_winsys(10873):new_window_surface返回0x3000
I / K2_ULS(10873):07/21/2015 17:24:38.293 PPTDROID
(0x2a79)0x400 66154示例powerworld AppHost
PLM a2k0b中等PauseHandlerActivityLifecycleCallbacks:onActivitySaveInstanceState
调用
I / Keyboard.Facilitator(614):onFinishInput()
W / InputMethodManagerService(449):窗口已经聚焦,忽略
焦点收益:
com.android.internal.view.IInputMethodClient$Stub$Proxy@4227f090
attribute=android.view.inputmethod.EditorInfo@423ba3a8,token =
android.os.BinderProxy@41f633d8
尝试这一个
LoginButton loginButton;
CallbackManager callbackManager;
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
loginButton =(LoginButton)findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList(public_profile,user_friends,email));
loginButton.registerCallback(callbackManager,new FacebookCallback< LoginResult>(){
@Override
public void onSuccess(LoginResult loginResult){
个人资料= Profile.getCurrentProfile();
profile.getProfilePictureUri(315,315);
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback(){
@Override
public void onCompleted(JSONObject object,GraphResponse response){
Log.v(LoginActivity,response.toString());
}
});
Bundle parameters = new Bundle();
parameters.putString(fields,id,name,email);
request.setParameters(parameters);
请求。 executeAsync();
}
@Override
public void onCancel(){
}
@Override
public void onError(FacebookException e){
e.printStackTrace();
}
});
并覆盖下方
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode,resultCode,data);
callbackManager.onActivityResult(requestCode,resultCode,data);
}
并在menifest中定义这个
< activity
android:name =com.facebook.FacebookActivityandroid:configChanges =keyboard | keyboardHidden | screenLayout | screenSize | orientation
android:label =@ string / app_name
android:theme =@ android:style / Theme.Translucent.NoTitleBar/>
I want to integrate Facebook signin in my android app. I am using Facebook-sdk-4.4.0. Using the LoginManager class method. But I am facing problem on running the following code-
FacebookSdk.sdkInitialize(getApplicationContext());
callbackmanager = CallbackManager.Factory.create();
// Set permissions
LoginManager.getInstance().logInWithReadPermissions((Activity)getContext(), Arrays.asList("email", "public_profile"));
LoginManager.getInstance().registerCallback(callbackmanager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject userInfo, GraphResponse graphResponse) {
try {
FacebookClientController.setUserId(userInfo.optString(ID));
FacebookClientController.setDisplayName(userInfo.optString(NAME));
FacebookClientController.setEmailAddress(userInfo.optString(EMAIL));
JSONObject picJson = userInfo.getJSONObject(PICTURE).getJSONObject("data");
FacebookClientController.setProfilePicUrl(picJson.optString("url"));
Log.d(LOGTAG, "\nUsername :" + FacebookClientController.getDisplayName());
Log.d(LOGTAG, "\nEmail :" + FacebookClientController.getEmailAddress());
Log.d(LOGTAG, "\nUserId :" + FacebookClientController.getUserId());
Log.d(LOGTAG, "\nProfilePicUrl :" + FacebookClientController.getProfilePicUrl());
} catch (JSONException e) {
Log.d(LOGTAG, "Json Error");
}
}
}
);
Bundle parameters = new Bundle();
parameters.putString(FIELDS, FB_REQUEST_FIELDS);
request.setParameters(parameters);
GraphRequest.executeBatchAsync(request);
Toast.makeText(getContext(), "Login successful" + loginResult.toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Log.d(LOGTAG, "On cancel");
}
@Override
public void onError(FacebookException error) {
Log.d(LOGTAG, error.toString());
}
});
}
I am getting the left screen in my app instead of the right screen which should come on running the above code. Can anyone tell me where can be the problem? Logcat:
--------- beginning of /dev/log/main
I/AppHost.Android(10873): Registered listener for handling onActivityResult: com.example.office.docsui.common.SignInController$5
--------- beginning of /dev/log/system
I/ActivityManager( 449): START u0 {act=NATIVE_WITH_FALLBACK cmp=com.example.office.powerworld/com.facebook.FacebookActivity (has extras)} from pid 10873
I/TelemetryLifeCycleState(10873): Activity Pause Start. Activity:1099625720,PPTActivity, AppState=3
I/ActivityManager( 449): START u0 {act=NATIVE_WITH_FALLBACK cmp=com.example.office.powerworld/com.facebook.FacebookActivity (has extras)} from pid 10873
I/TelemetryLifeCycleState(10873): Activity Pause End. Activity:1099625720,PPTActivity, AppState=2
I/TelemetryLifeCycleState(10873): Activity Created. Activity:1107534680,com.facebook.FacebookActivity
I/AppHost.Android(10873): onActivityStarted, foregroundActivityCount=1, mEventsEnabled= true, mResumeEnabled=false
I/AppHost.Android(10873): this is not an office activity::com.facebook.FacebookActivity
I/TelemetryLifeCycleState(10873): Activity Resume Start. Activity:1107534680,com.facebook.FacebookActivity, AppState=2
I/TelemetryLifeCycleState(10873): Activity Resume End. Activity:1107534680,com.facebook.FacebookActivity, AppState=3, suspensionTime=54215
I/TelemetryLifeCycleState(10873): Activity Pause Start. Activity:1107534680,com.facebook.FacebookActivity, AppState=3
I/TelemetryLifeCycleState(10873): Activity Pause End. Activity:1107534680,com.facebook.FacebookActivity, AppState=2
I/TelemetryLifeCycleState(10873): Activity Created. Activity:1107673504,com.facebook.FacebookActivity
D/dalvikvm(10873): GC_FOR_ALLOC freed 2064K, 20% free 8974K/11096K, paused 27ms, total 30ms
I/AppHost.Android(10873): onActivityStarted, foregroundActivityCount=1, mEventsEnabled= true, mResumeEnabled=false
I/AppHost.Android(10873): this is not an office activity::com.facebook.FacebookActivity
I/TelemetryLifeCycleState(10873): Activity Resume Start. Activity:1107673504,com.facebook.FacebookActivity, AppState=2
I/TelemetryLifeCycleState(10873): Activity Resume End. Activity:1107673504,com.facebook.FacebookActivity, AppState=3, suspensionTime=54303
D/mali_winsys(10873): new_window_surface returns 0x3000
D/mali_winsys(10873): new_window_surface returns 0x3000
D/mali_winsys(10873): new_window_surface returns 0x3000
D/mali_winsys(10873): new_window_surface returns 0x3000
I/Keyboard.Facilitator( 614): onFinishInput()
I/ActivityManager( 449): Displayed com.example.office.powerworld/com.facebook.FacebookActivity: +346ms
I/ActivityManager( 449): Displayed com.example.office.powerworld/com.facebook.FacebookActivity: +346ms
D/mali_winsys(10873): new_window_surface returns 0x3000
D/mali_winsys(10873): new_window_surface returns 0x3000
I/K2_ULS (10873): 07/21/2015 17:24:38.293 PPTDROID (0x2a79) 0x40066154 Example powerworld AppHost PLM a2k0b Medium PauseHandlerActivityLifecycleCallbacks:onActivitySaveInstanceState called
I/Keyboard.Facilitator( 614): onFinishInput()
W/InputMethodManagerService( 449): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4227f090 attribute=android.view.inputmethod.EditorInfo@423ba3a8, token = android.os.BinderProxy@41f633d8
Try this one
LoginButton loginButton;
CallbackManager callbackManager;
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("public_profile", "user_friends", "email"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Profile profile = Profile.getCurrentProfile();
profile.getProfilePictureUri(315, 315);
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.v("LoginActivity", response.toString());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
e.printStackTrace();
}
});
and override below method
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
and define this in menifest
<activity
android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
这篇关于Facebook活动未正确载入Facebook-sdk 4.4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!