我正在尝试在我的 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();}
}
}