我的Android Facebook应用程序无法打开FB会话

时间:2013-08-01 18:53:14

标签: android facebook session login sdk

我跟着Facebook SDK for Android getting started tutorial并且“if(session.isOpened())”语句从未通过。我的主要活动java代码是教程的精确副本。
我读了散列键的错误,所以我在教程中的步骤4的疑难解答部分添加了代码,并将logcat hashkey复制到我的Facebook Dev帐户,但没有区别。
- 我的项目目标:Android 4.3(18)
-facebook-Android的SDK-3.0.2
-java 1.7
- 在模拟器中测试

我应该检查一下吗?

package com.firstandroidapp;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import com.facebook.*;
import com.facebook.model.*;
import android.widget.TextView;
import android.content.Intent;

public class MainActivity extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // start Facebook Login
    Session.openActiveSession(this, true, new Session.StatusCallback() {

      // callback when session changes state
      @Override
      public void call(Session session, SessionState state, Exception exception) {
        if (session.isOpened()) {
          Log.d("CHECKPOINT", "Session opened!");

          // make request to the /me API
          Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

            // callback after Graph API response with user object
            @Override
            public void onCompleted(GraphUser user, Response response) {
              if (user != null) {
                TextView welcome = (TextView) findViewById(R.id.welcome);
                welcome.setText("Hello " + user.getName() + "!");
              }
            }
          });
        }
        else
        {
           Log.d("CHECKPOINT", "No open session");
        }
      }
    });
  }

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

}

0 个答案:

没有答案