Android应用程序上的Facebook SDK,在模拟器上工作但在手机上将永远保持加载

时间:2012-01-07 11:50:23

标签: android facebook login sdk loading

我已经按照facebooks教程设置了sso密钥,并将sdk集成到我的代码中。登录Facebook后,facebook.authorize它将我带到一个新屏幕,只是说“加载”并坐在那里。

它可以在模拟器上运行但不是我的愿望HD, 我试过添加“,Facebook.FORCE_DIALOG_AUTH”,它对我不起作用。

图片只是有一条消息说“正在加载......”

非常感谢!

Facebook facebook = new Facebook("MyAppID");
String id,name;
TextView t1;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
        t1 = (TextView) findViewById(R.id.id);

    }

        facebook.authorize(this,new String[] {"user_about_me"},new DialogListener() {
            @Override
            public void onComplete(Bundle values) {
                 GET();
            }

            @Override
            public void onFacebookError(FacebookError error) {}

            @Override
            public void onError(DialogError e) {}

            @Override
            public void onCancel() {}
        });

}
}


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

 public void GET(){
    try {
        JSONObject json1 = new JSONObject(facebook.request("me"));

        if(json1 != null)
        {
            for(int i=0;i<json1.length();i++)
            {
                id = json1.getString("id");                     
                name = json1.getString("name");                 
            }
        }

        t1.setText(id + "," + name);

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   

   }

1 个答案:

答案 0 :(得分:0)

你写过这一行......

Facebook facebook = new Facebook(&#34; appid&#34;);

字符串不应该是&#34; appid&#34;但来自facebook的真实app id。

登录您的帐户并从此处获取Facebook ID ...

developers.facebook.com/apps/?action=create