简体   繁体   English

无法通过Facebook SDK登录

[英]Unable to login through Facebook SDK

I was trying to integrate Facebook SDK into an Android app with the help of official tutorial provided on Facebook . 我试图借助Facebook提供的官方教程将Facebook SDK集成到Android应用中。 I have followed all the steps correctly and my application contains no compilation errors. 我正确地遵循了所有步骤,并且我的应用程序没有编译错误。 But when I try to test it on a live device I am getting the error as follows: 但是,当我尝试在实时设备上对其进行测试时,出现如下错误:

The page you requested cannot be displayed right now. It may be temporarily unavailable, the link you clicked might be broken or expired, or you may have not the permission to view this page.

I am not able to understand the reason for this error. 我无法理解此错误的原因。 Please help! 请帮忙!

Code: 码:

MainActivity.java MainActivity.java

package com.example.myfbapp;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.model.GraphUser;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Session.openActiveSession(this, true, new Session.StatusCallback(){

        @Override
        public void call(Session session, SessionState state,
                Exception exception) {
            if(session.isOpened()){
                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if(user!=null){
                            TextView tvWelcome=(TextView)findViewById(R.id.tvWelcome);
                            tvWelcome.setText("Welcome "+user.getName()+"!");
                        }
                    }
                });
            }
        }

    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

activity_main.xml activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/tvWelcome"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="Welcome!" />

</RelativeLayout>

AndroidManifest.xml AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfbapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="false"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.myfbapp.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data android:value="@string/app_id" android:name="com.facebook.sdk.ApplicationId"/>
    <activity android:name="com.facebook.LoginActivity"></activity>
</application>

</manifest>

Updating the Facebook app on your device may solve the problem , 在您的设备上更新Facebook应用可以解决该问题

It may not work if the Facebook app is not updated. 如果未更新Facebook应用程序,则可能无法正常工作。 I had the same issue and updating solved it 我有同样的问题,更新解决了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM