每次我在模拟器上测试我的应用程序时。 “ AppName发生错误。请稍后再试。”我已在清单.XML中启用了Internet访问。

这是我到目前为止的内容:

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);
    }
}




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...


Eclipse控制台输出:

[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-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 }


实际上,我只是使用Facebook本身为Android提供的Facebook SDK,但我无法使其正常工作。有任何想法吗?

最佳答案

您使用的是friend_location而不是friends_location

检查logcat的最后几行:


  05-01 02:21:01.601:调试/ Facebook-WebView(234):Web视图加载URL:fbconnect:// success /?error = invalid_scope&error_description =不支持+ scope%3A +%27friend_location ...


顺便说一句,最好将至少一些日志输出添加到public void onFacebookError(FacebookError error) {}catch (Exception e) {} catch (FacebookError f) {}。它将为您(和我们)节省很多时间:)

08-06 16:25