无法通过Facebook SDK登录

时间:2013-08-06 07:05:30

标签: android facebook facebook-android-sdk

我试图在Facebook提供的官方教程的帮助下将Facebook SDK集成到Android应用程序中。我已正确执行所有步骤,并且我的应用程序不包含编译错误。但是当我尝试在现场设备上测试时,我收到的错误如下:

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.

我无法理解此错误的原因。请帮忙!

代码:

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中

<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

<?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>

1 个答案:

答案 0 :(得分:1)

更新设备上的Facebook应用可能会解决问题

如果Facebook应用未更新,它可能无效。 我有同样的问题,更新解决了它