0

我正在尝试在我的 android 设备上运行 facebook 应用程序。该应用程序是一个简单的发布按钮。在模拟器中运行正常,但在设备中,在调试模式(eclipse)中捕获了以下消息。

error message: {"error":{"message":"(#100) Missing message or attachment","type":"OAuthException","code":100}}

有人知道出了什么问题吗?谢谢!

我的活动代码如下

package f.b;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.facebook.android.AsyncFacebookRunner.RequestListener;
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.AsyncFacebookRunner;

public class NewFaceAppActivity extends Activity {
        private final String id = "";//my id here
    private final String [] permissoes = {"publish_stream"};
    private SharedPreferences mPrefs;
    AsyncFacebookRunner mAsyncRunner;
    Facebook facebook = new Facebook(id);
    String access_token = "";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    login();
}

public void login(){

    /*
     * Get existing access_token if any
     */
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    access_token = mPrefs.getString("access_token", "x");
    long expires = mPrefs.getLong("access_expires", -1);
    if(access_token != null) {
        facebook.setAccessToken(access_token);
    }
    if(expires != 0) {
        facebook.setAccessExpires(expires);
    }
    /*
     * Only call authorize if the access_token has expired.
     */
    if(facebook.isSessionValid() == false) {

        facebook.authorize(this, permissoes, -1, new DialogListener() {
            @Override
            public void onComplete(Bundle values) {
                SharedPreferences.Editor editor = mPrefs.edit();
                editor.putString("access_token", facebook.getAccessToken());
                editor.putLong("access_expires", facebook.getAccessExpires());
                editor.commit();
            }

            @Override
            public void onFacebookError(FacebookError error) {}

            @Override
            public void onError(DialogError e) {}

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

}

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

@Override
public void onResume() {    
    super.onResume();
    facebook.extendAccessTokenIfNeeded(this, null);
}

public void logout(){
    mAsyncRunner.logout(getBaseContext(), new RequestListener() {
          @Override
          public void onComplete(String response, Object state) {}

          @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) {}

        });
}

public void postar(View v){
    //if(facebook.isSessionValid()){
        EditText et = (EditText) findViewById(R.id.et);
        Bundle parameters = new Bundle();
        String msg = et.getText().toString();
        String r = "";
        parameters.putString(this.access_token, msg );
        try {
            r = facebook.request("me/feed", parameters, "POST");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Toast.makeText(this, r, Toast.LENGTH_LONG);
        //}else{login();}
    }
}
4

1 回答 1

3

我看不出这在模拟器中是如何工作的,您只是没有将消息参数名称放入包中。

正如您在Post object的文档中看到的那样,参数的名称是“message”,并且您插入了带有访问令牌作为名称的消息参数。它应该是:

Bundle parameters = new Bundle();
String msg = et.getText().toString();
parameters.putString("message", msg);

无需添加访问令牌,SDK 会为您完成。

于 2012-05-14T06:43:47.830 回答