我正在使用facebook sdk让用户将消息发布到他的墙上。 我正在使用现有的facebook教程: Facebook tutorial
这里是我使用的主要代码:
package com.greatapp;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import com.facebook.android.*;
import com.facebook.android.Facebook.*;
public class MyGreatActivity extends Activity {
Facebook facebook = new Facebook("YOUR_APP_ID");
String FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*
* Get existing access_token if any
*/
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[] {}, 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);
}
}
我使用postToWall(String message)方法扩展了这个基本代码。这很好。
我通过其他活动的意图来称呼它。我希望所有这些Facebook帖子都在后台处理而不显示进度条或类似的东西。这可能吗?
答案 0 :(得分:0)
facebook android SDK有两个facebook类可供使用:https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/android/AsyncFacebookRunner.java
你可以使用它与另一个完全相同的方式,只需要构建它,你可以这样做:
Facebook fb = new Facebook(appid);
AsyncFacebookRunner async = new AsyncFacebookRunner(fb);
async.request("me", new SimpleDialogListener());