开发者

Facebook OAuth on Android

Every time I test out my app on the emulator. "An error occurred with AppName. Please try again later." I have enabled internet access in the manifest .XML.

This is what I have so far:

package com.xxxxxx;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
import com.facebook.android.Util;

public class LunchtimeActivity extends Activity {

    Facebook facebook = new Facebook("xxxxxxxxxxxxxx");

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

        facebook.authorize(this, new String [] {"user_location", "friend_location", "user_events", "friends_events"}, new DialogListener() {
            @Override
            public void onComplete(Bundle values) {}

            @Override
            public void onFacebookError(FacebookError error) {}

            @Override
            public void onError(DialogError e) {}

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

        Bundle parameters = new Bundle();
        parameters.putString( "fields", "id,name" ); 

        try {
            String response = facebook.request( "me/friends", parameters ); 

            JSONObject json = Util.parseJson( response );

            JSONArray data = json.getJSONArray( "data" );

            for ( int i = 0; i < data.length(); i++ )
            {
                JSONObject friend = data.getJSONObject( i );

                String id = friend.getString( "id" );
                String name = friend.getString( "name" );
                Log.v("JSON", id);
                Log.v("JSON", name);
            }
        }
        catch (Exception e) {}
        catch (FacebookError f) {}

        TextView tv = new TextView(this);
        tv.setText("Hello, Android");
        setContentView(tv);
    }

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

        facebook.authorizeCallback(requestCode, resultCode, data);
    }
}

Facebook OAuth on Android

Logcat output:

...
05-01 02:21:01.601: DEBUG/Facebook-WebView(234): Webview loading URL: fbconnect://success/?error=invalid_scope&error_description=Unsupported+scope%3A+%27friend_location...

Eclipse console output:

[2011-05-01 02:18:57 - Lunchtime_1.0] ------------------------------
[2011-05-01 02:18:57 - Lunchtime_1.0] Android Launch!
[2011-05-01 02:18:57 - Lunchtime_1.0] adb is running normally.
[2011-05-01 02:18:57 - Lunchtime_1.0] Performing com.lunch.LunchtimeActivity activity launch
[2011-05-01 02:18:57 - Lunchtime_1.0] Automatic Target Mode: Preferred AVD 'Now' is not available. Launching new emulator.
[2011-05-01 02:18:57 - Lunchtime_1.0] Launching a new emulator with Virtual Device 'Now'
[2011-05-01 02:19:03 - Emulator] 2011-05-01 02:19:03.471 emulator[3575:903] Warning once: This application, or a library it uses, is using NSQuickDrawView, which has been deprecated. Apps should cease use of QuickDraw and move to Quartz.
[2011-05-01 02:19:03 - Lunchtime_1.0] New emulator found: emulator-5554
[2011开发者_Python百科-05-01 02:19:03 - Lunchtime_1.0] Waiting for HOME ('android.process.acore') to be launched...
[2011-05-01 02:20:20 - Lunchtime_1.0] WARNING: Application does not specify an API level requirement!
[2011-05-01 02:20:20 - Lunchtime_1.0] Device API version is 7 (Android 2.1-update1)
[2011-05-01 02:20:20 - Lunchtime_1.0] HOME is up on device 'emulator-5554'
[2011-05-01 02:20:20 - Lunchtime_1.0] Uploading Lunchtime_1.0.apk onto device 'emulator-5554'
[2011-05-01 02:20:20 - Lunchtime_1.0] Installing Lunchtime_1.0.apk...
[2011-05-01 02:20:39 - Lunchtime_1.0] Success!
[2011-05-01 02:20:39 - Lunchtime_1.0] Starting activity com.lunch.LunchtimeActivity on device emulator-5554
[2011-05-01 02:20:43 - Lunchtime_1.0] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.lunch/.LunchtimeActivity }

I'm literally just using the Facebook SDK provided by Facebook itself for Android and I can't make it work. Any ideas?


You're using friend_location instead of friends_location

Check the last lines of the logcat:

05-01 02:21:01.601: DEBUG/Facebook-WebView(234): Webview loading URL: fbconnect://success/?error=invalid_scope&error_description=Unsupported+scope%3A+%27friend_location...

BTW, it is a good idea to add at least some log output to public void onFacebookError(FacebookError error) {} and catch (Exception e) {} catch (FacebookError f) {}. It will save you (and us) a lot of time :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜