Facebook Android集成:不应传递读取权限错误

时间:2014-08-08 11:14:32

标签: android facebook permissions authorization

我正在开发一个Android应用程序,用户应该可以使用Facebook帐户登录。该应用程序在前5-10分钟工作。我可以看到我被提示给予/拒绝权限的布局。

当我尝试登录时,它会显示来自Facebook API的"Loading"消息,然后返回到之前的布局。

我收到的错误消息是:"Should not pass a read () permission to a request for publish or manage authorization"

感谢您解决此问题的任何帮助..

package com.kampusbilisim.sencebence;

import java.io.*;
import java.net.*;
import org.json.*;

import com.facebook.android.*;
import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.facebook.android.Facebook.DialogListener;

import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.*;
import android.util.Log;
import android.view.*;
import android.widget.*;

@SuppressWarnings("deprecation")
public class FullscreenActivity extends Activity {
    String TAG = "SenceBence";

    private static String APP_ID = "659712077445489";
    private Facebook facebook;
    String FILENAME = "AndroidSSO_data";
    private SharedPreferences mPrefs;
    Button btnFbLogin;
    private AsyncFacebookRunner mAsyncRunner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_fullscreen);

        facebook = new Facebook(APP_ID);
        mAsyncRunner = new AsyncFacebookRunner(facebook);

        btnFbLogin = (Button) findViewById(R.id.button1);
        btnFbLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                loginToFacebook();
                Toast.makeText(FullscreenActivity.this, "Logging in.. ", Toast.LENGTH_SHORT).show();
            }
        });

        TextView tv = (TextView) findViewById(R.id.girisyazisibeyaz);
        tv.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/AvenirNextLTPro-Bold.otf"));
    }

    @SuppressWarnings("deprecation")
    public void loginToFacebook() {
        mPrefs = getPreferences(MODE_PRIVATE);
        String access_token = mPrefs.getString("access_token", null);
        long expires = mPrefs.getLong("access_expires", 0);

        if (access_token != null) {
            facebook.setAccessToken(access_token);
        }

        if (expires != 0) {
            facebook.setAccessExpires(expires);
        }
        if (!facebook.isSessionValid()) {
            facebook.authorize(this, new String[] { "email" , "publish_actions", "publish_checkins", "publish_stream" },  
                    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
                    SharedPreferences.Editor editor = mPrefs.edit();
                    editor.putString("access_token", facebook.getAccessToken());
                    editor.putLong("access_expires", facebook.getAccessExpires());
                    editor.commit();
                }
                @Override
                public void onError(DialogError error) {
                    // Function to handle error
                }
                @Override
                public void onFacebookError(FacebookError fberror) {
                    // Function to handle Facebook errors
                }
            });
        }
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
    }
}

0 个答案:

没有答案