Facebook sdk没有在平板电脑(Android)工作,它在手机上工作得很好

时间:2014-09-17 09:18:44

标签: android facebook facebook-sdk-3.0

在我的应用程序中,我使用Facebook SDK登录应用程序。它可以在手机中没有任何错误的情况下正常工作,但如果我在平板电脑上测试它,它授权用户并生成访问令牌,但不能获取用户数据。我按照此链接获取此代码http://sunil-android.blogspot.in/2013/08/facebook-integration-with-android-app.html

我正在分享我导入的代码部分

 /**
     * Function to login into facebook
     * */

    @SuppressWarnings("deprecation")
    public void loginToFacebook() {

        String access_token = obj_pref.get_access_token();
        long expires = obj_pref.get_access_expires();

        if (access_token != null) {
            facebook.setAccessToken(access_token);
            Log.d("FB Sessions", "" + facebook.isSessionValid());
        }

        if (expires != 0) {
            facebook.setAccessExpires(expires);
        }

        if (!facebook.isSessionValid()) {
            facebook.authorize(this, new String[] { "email", "publish_stream",
                    "user_birthday" }, new DialogListener() {

                @Override
                public void onCancel() {
                    // Function to handle cancel event
                }

                @Override
                public void onComplete(Bundle values) {
                    // Function to handle complete event
                    // Edit Preferences and update facebook acess_token

                    obj_pref.set_access_token(facebook.getAccessToken());

                    obj_pref.set_access_expires(facebook.getAccessExpires());
                    getProfileInformation();

                }

                @Override
                public void onError(DialogError error) {
                    // Function to handle error
                }

                @Override
                public void onFacebookError(FacebookError fberror) {
                    // Function to handle Facebook errors
                }
            });
        } else if (facebook.isSessionValid()) {

            getProfileInformation();

        }
    }

    /**
     * Get Profile information by making request to Facebook Graph API
     * */
    @SuppressWarnings("deprecation")
    public void getProfileInformation() {
        mAsyncRunner.request("me", new RequestListener() {
            @Override
            public void onComplete(String response, Object state) {
                Log.d("Profile", response);
                String json = response;
                try {
                    // Facebook Profile JSON data
                    JSONObject profile = new JSONObject(json);

                    obj_pref.set_user_id(profile.getString("email"));

                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            new send_fb_data().execute();
                     // upload user data to my database server
                        }

                    });

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onIOException(IOException e, Object state) {
            }

            @Override
            public void onFileNotFoundException(FileNotFoundException e,
                    Object state) {
            }

            @Override
            public void onMalformedURLException(MalformedURLException e,
                    Object state) {
            }

            @Override
            public void onFacebookError(FacebookError e, Object state) {
            }
        });

任何人都可以帮我解决这个问题,即使在平板电脑中它也不会给出任何错误......

0 个答案:

没有答案