其他分享
首页 > 其他分享> > android-找不到客户端令牌,请设置客户端令牌

android-找不到客户端令牌,请设置客户端令牌

作者:互联网

我正在尝试使用android中的facebook创建登录名,并且遇到了这个问题.我不确定我看不到或设置了什么.

我尝试设置应用程序令牌/客户端机密,但是它一直失败.

下面是我的代码:
清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.test.app">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".SplashScreenActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".FacebookLoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.FACEBOOK_LOGIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

        </activity>
        <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"
            tools:replace="android:theme" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAINACTIVITY" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
    </application>

    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

Facebook登录活动

 package com.test.app;
    public class FacebookLoginActivity extends AppCompatActivity {

        private TextView info;

        private LoginButton loginButton;
        private CallbackManager callbackManager;

        @Override
        public void onCreate(Bundle bundle) {
            super.onCreate(bundle);
            FacebookSdk.sdkInitialize(getApplicationContext());

            callbackManager = CallbackManager.Factory.create();
            setContentView(R.layout.facebook_login);
            info = (TextView) findViewById(R.id.info);
            loginButton = (LoginButton) findViewById(R.id.login_button);

            loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    info.setText(
                            "User ID: "
                                    + loginResult.getAccessToken().getUserId()
                                    + "\n" +
                                    "Auth Token: "
                                    + loginResult.getAccessToken().getToken()
                    );
                }

                @Override
                public void onCancel() {
                    info.setText("Login attempt canceled.");
                }

                @Override
                public void one rror(FacebookException error) {
                    info.setText("Login attempt failed.");
                }
            });
        }

        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            callbackManager.onActivityResult(requestCode, resultCode, data);

        }
    }

错误

Caused by: java.lang.IllegalStateException: No Client Token found, please set the Client Token.
                      at com.facebook.internal.Validate.hasClientToken(Validate.java:162)
                      at com.facebook.login.DeviceAuthDialog.startLogin(DeviceAuthDialog.java:178)
                      at com.facebook.login.DeviceAuthMethodHandler.showDialog(DeviceAuthMethodHandler.java:51)
                      at com.facebook.login.DeviceAuthMethodHandler.tryAuthorize(DeviceAuthMethodHandler.java:42)
                      at com.facebook.login.LoginClient.tryCurrentHandler(LoginClient.java:254)
                      at com.facebook.login.LoginClient.tryNextHandler(LoginClient.java:216)
                      at com.facebook.login.LoginClient.authorize(LoginClient.java:121)
                      at com.facebook.login.LoginClient.startOrContinueAuth(LoginClient.java:102)
                      at com.facebook.login.LoginFragment.onResume(LoginFragment.java:153)
                      at android.support.v4.app.Fragment.performResume(Fragment.java:2230)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1343)
                      at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1523)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1585)
                      at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:2842)
                      at android.support.v4.app.FragmentController.dispatchResume(FragmentController.java:223)
                      at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:509)
                      at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:498)
                      at android.app.Activity.performResume(Activity.java:6807)
                      at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3406)
                      at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3469) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2732) 
                      at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 

解决方法:

您需要像这样将应用程序客户端令牌添加到AndroidManifest中:

<meta-data
        android:name="com.facebook.sdk.ClientToken"
        android:value="@string/facebook_client_token"/>

您可以在Facebook信息中心中找到您的应用客户端令牌->设置->高级(在“安全性”部分)

标签:facebook,facebook-android-sdk,android
来源: https://codeday.me/bug/20191111/2022833.html