我有几个问题需要我找到解决方案。我正在使用LoginButton,但它无法正常工作。我列出了优先级问题,即第一个问题具有最高优先级。我想使用Facebook Sdk 4.0但我是面临以下问题。
Q1。 Facebook按钮状态问题:在正常的Facebook登录流程的情况下,它工作正常,但如果我在给予应用程序权限后立即强行关闭应用程序(即,如果我使用此语句设置权限:
mLoginWithFaceBook.setReadPermissions(Arrays.asList("public_profile", "email"));
) 使用facebook sdk的OK按钮,之后我无法控制登录按钮的状态。
我有以下问题:
- 在上面的用例中没有调用回调方法。实际上,我想在获取用户的facebook信息后成功从facebook注销,但在这种情况下,由于没有调用回调,所以我无法做到。因此,当用户再次打开应用程序时,按钮状态无法正确维护。在正常情况下,我正在进行回调注销。
如何解决上述问题?
Q2。 Facebook按钮文字问题:我希望FacebookButton的文本保持不变,所以我在字符串文件中为所有三种情况添加了以下内容
<string name="com_facebook_loginview_log_out_button">Log in with Facebook</string>
<string name="com_facebook_loginview_log_in_button">Log in with Facebook</string>
<string name="com_facebook_loginview_log_in_button_long">Log in with Facebook</string>
但在默认情况下&#34; com_facebook_loginview_log_in_button_long&#34;文本看起来正确(即没有宽度和高度问题),但对于其他情况,我只看到登录(即com_facebook_loginview_log_in_button和com_facebook_loginview_log_in_button_long 按钮的文字)。
如果我为Loginbutton的高度和宽度执行match_parent(此处LoginButton&#39; s的父级占据屏幕的整个宽度),则按钮显示上述非工作情况的全文。
实际上我想这样做:
1 。按钮文字应使用Facebook登录但按钮的宽度应为wrap_content
2 。无论用例如何,当用户点击使用Facebook登录时,sdk必须要求权限(即通过“确定”和“取消”按钮)。它无需显示 您需要先注销此用户的任何提醒,我的登录Facebook 正在显示。
我编写以下代码段来实现此目的,但它没有帮助:
将LoginButton添加到LinearLayout ,它占据整个屏幕的宽度(我不想这样做,它应该是包装内容,但不能像上面提到的那样为我工作)
在字符串文件中添加了三个字符串
<string name="com_facebook_loginview_log_out_button">Log in with Facebook</string>
<string name="com_facebook_loginview_log_in_button">Log in with Facebook</string>
<string name="com_facebook_loginview_log_in_button_long">Log in with Facebook</string>
并使用以下代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
if (AccessToken.getCurrentAccessToken() != null && com.facebook.Profile.getCurrentProfile() != null){
revokePermissions();//this is my method for revoking the permissions which i was given previously.
logout();
}
mCallbackManager = CallbackManager.Factory.create();
}
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mLoginWithFaceBook.setReadPermissions(Arrays.asList("public_profile", "email"));
// If using in a fragment
mLoginWithFaceBook.setFragment(this);
// Callback registration
mLoginWithFaceBook.registerCallback(mCallbackManager, new FaceBookListener());
mLoginWithFaceBook.setOnClickListener(this);
}
private class FaceBookListener implements FacebookCallback<LoginResult> {
private ProfileTracker mProfileTracker;
@Override
public void onSuccess(LoginResult loginResult) {
final String accessToken = loginResult.getAccessToken().getToken();
mProfileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile profile) {
if (profile != null) {
//doing some work here
}
};
mProfileTracker.startTracking();
}
@Override
public void onCancel() {
revokePermissions();
LoginManager.getInstance().logOut();
}
@Override
public void onError(FacebookException exception) {
revokePermissions();
LoginManager.getInstance().logOut();
}
}
如果您遇到同样的问题,请提供任何帮助。将提供任何帮助 赞赏。