0

Android アプリに Facebook SSO を実装しようとしています。ログイン プロセスが完了すると、ネイティブの Facebook アプリが開き、「500: 内部サーバー エラー」が表示されます。

どんな提案でも大歓迎です。これが私のコードです

public class FacebookUtil {

    public static Facebook facebook = new Facebook(AppConstants.FACEBOOK_APP_ID);
    String FILENAME = "AndroidSSO_data";
    private static SharedPreferences mPrefs;
    private static Context mContext;
    private static  boolean isSucess;
    private static FacebookSucessListener mFacebookSucessListener;
     public static final String FB_APP_SIGNATURE ="xxxxxxxxxxxxxxxxxxx"; 
    public interface FacebookSucessListener {
        public void onSucess(boolean isSucess);
    }
    public static void postToWall(){
        facebook.dialog(mContext, "feed" , new DialogListener(){
            public void onCancel() {

            }
            public void onComplete(Bundle arg0) {

            }

            public void onError(DialogError arg0) {

            }

            public void onFacebookError(FacebookError arg0) {

            }});
    }

    /*
     * Function to update status
     * @param facebook acesstoken acess token
     * @param  String message to post
     */
    public static void updateStatus(String accessToken, final String aMsgToShare){
        try {
            Bundle bundle = new Bundle();
            bundle.putString("message", aMsgToShare);
            bundle.putString(Facebook.TOKEN, accessToken);
            String response = facebook.request("me/feed",bundle,"POST");
            if(response.contains("Duplicate status message"))
                Toast.makeText(mContext, "Duplicate message can not post", Toast.LENGTH_SHORT).show();
            else if (response.contains("The user hasn't authorized the application to perform this action"))
                Toast.makeText(mContext, "The user hasn't authorized the application to perform this action",Toast.LENGTH_SHORT).show();
            else
                Toast.makeText(mContext,"Posted Successfuly", Toast.LENGTH_SHORT).show();
        } catch (MalformedURLException e) {
            Log.e("MALFORMED URL",""+e.getMessage());

        } catch (IOException e) {

        }
    }
    /*
     * To logout from facebook
     * @param Activity activity
     * return response
     */
    public static String logoutFacebook(Activity aActivity){
        String resonse = "";
        try {
            String response = facebook.logout(aActivity.getApplicationContext());
        } catch (Exception e) {
            Log.e("LogoutException",""+e.getMessage());
        }
        return resonse;
    }


    /*
     * TO start the  facebook login process
     * @param Activity activity
     * @param SharedPreferences pref
     * return true in case of sucess false otherwise
     */
    public static void startLoginProcess(final Activity aActivity,final SharedPreferences mPrefs,FacebookSucessListener facebookSucessListener)
    {
        try{
            mFacebookSucessListener = facebookSucessListener;
        }catch(Exception e){}

        /*
         * Get existing access_token if any
         */
        mContext=aActivity;
        String access_token = mPrefs.getString("fb_access_token", null);
        long expires = mPrefs.getLong("fb_expire_time", 0);
        if(access_token != null) {
            facebook.setAccessToken(access_token);
        }
        if(expires != 0) {
            facebook.setAccessExpires(expires);
        }
        boolean isSessionValid  = facebook.isSessionValid();
        if(!isSessionValid)
        {
            //Facebook.FORCE_DIALOG_AUTH
            facebook.authorize( aActivity, AppConstants.permissions, 1, new DialogListener() {
                public void onComplete(Bundle values) {
                    String token = values.getString(Facebook.TOKEN);
                    SharedPreferences.Editor editor = mPrefs.edit();
                    editor.putString("fb_access_token", facebook.getAccessToken());
                    editor.putLong("fb_expire_time", facebook.getAccessExpires());
                    editor.putBoolean("is_fb_logged_in", true);
                    editor.commit();
                    mFacebookSucessListener.onSucess(true);
                }

                public void onFacebookError(FacebookError error) {
                    mFacebookSucessListener.onSucess(false);
                    Log.e("Facebook-onFacebookError", error.getMessage());
                    Toast.makeText(aActivity, "Error: "+ error.getMessage(), 600).show();
                }
                public void onError(DialogError e) {
                    mFacebookSucessListener.onSucess(false);
                    Log.e("Facebook-onError", e.getMessage());
                    Toast.makeText(aActivity, "Error: "+ e.getMessage(), 600).show();

                }

                public void onCancel() {

                }
            });
        }
        else {
            mFacebookSucessListener.onSucess(true);
        }


    }
    final class PostDialogListener implements DialogListener {
        public void onComplete(Bundle values) {

        }

        public void onFacebookError(FacebookError error) {
            Log.e("Facebook-onFacebookError", error.getMessage());
        }

        public void onError(DialogError error) {
            Log.e("Facebook-onFacebookError", error.getMessage());
        }

        public void onCancel() {

        }
    }


}
4

2 に答える 2

5

最後に、問題を解決しました。ウィンドウ 7 で CMD を使用して生成していた Has キーが間違っていました。だから私はこれをプログラムで生成しました。

private void getHashKey()
{
        PackageInfo info;
        try {
        info = getPackageManager().getPackageInfo("your app package name", PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
                   MessageDigest md;
        md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
                   //String something = new String(Base64.encode(md.digest(), 0));
                     String something = new String(Base64.encode(md.digest(),0));
                   Log.e("**** Hash Key", something);
        } 
        }
        catch (NameNotFoundException e1) {
        Log.e("name not found", e1.toString());
        }

        catch (NoSuchAlgorithmException e) {
        Log.e("no such an algorithm", e.toString());
        }
        catch (Exception e){
        Log.e("exception", e.toString());
        }

}
于 2012-10-15T05:01:11.820 に答える
1

こちらを参考にしてください

Android シングル サインオン

そして、これも試してみてください...

"Enhanced Auth Dialog"disabled in application settingsあなたの問題を解決する必要があります。

于 2012-09-30T12:06:25.817 に答える