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