在墙上张贴短信时遇到问题。我原以为这些应用程序会登录fb并在墙上发布短信,但我的墙上什么也没发布。
以下是我的代码登录部分与Facebook指南相同,我只是添加了权限"发布流"
public class FB_trial extends Activity {
Facebook facebook = new Facebook("app_id");
private AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
private SharedPreferences mPrefs;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fb_trial);
/*
* The following is tutorial sample code
*/
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
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()) {
facebook.authorize(this, new String[] {"publish_stream"}, 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() {}
});
}
//end of the login sample code
//post wall fx
Bundle params = new Bundle();
params.putString("message", "Fb testing message");
params.putString("access_token", access_token);
mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request("me/feed", params, "POST", new RequestListener(){
@Override
public void onComplete(String response, Object state) {
System.out.println("post wall success");
}
@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) {}
}, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_fb_trial, menu);
return true;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
}
日志中显示"wallpostsuccess"消息(这是否意味着请求已完成?)但是我在墙上找不到那根柱子。
您可以使用对话框张贴到墙上:
Bundle params = new Bundle();
params.putString("link", linkgame);
params.putString("name", subject);
params.putString("description", content);
params.putString("picture", iconUrl);
facebook.dialog(((Activity) ctx).getParent(), "feed", params,
new DialogListener() {
public void onComplete(Bundle values) {
}
public void onFacebookError(FacebookError error) {}
public void onError(DialogError e) {}
public void onCancel() {}
});