在官方的 facebook 开发人员教程中,他们说在 facebook 上的用户 Wall 中发布就像写这行一样简单:
mFacebook.dialog(context, "feed", new PostDialogListener());
但是当我尝试使用它时,它一直要求我创建 PostDialogListener 类。这不是包含在 facebook sdk 中吗?我在哪里可以找到这门课?
而且,要注销,我必须使用这个:
mAsyncRunner.logout(getContext(), 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) {}
});
然后我被要求创建 getContext() 方法。
Facebook的教程很不完整,我现在该怎么办?谢谢!
编辑:我的 facebook 活动非常简单,我只是连接并从用户那里检索数据,然后将其传递给另一个活动。我想实现一个注销方法,并要求用户在登录后在墙上发帖(那将在另一个活动中)
public class FacebookConnectActivity extends Activity {
private static final String TAG_JSON = "json";
Facebook facebook = new Facebook("12121212112");
AsyncFacebookRunner mAsyncRunner;
private SharedPreferences mPrefs;
JSONObject json;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resgatar_produto_layout);
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);
}
if(!facebook.isSessionValid()) {
facebook.authorize(this, new String[] {"email", "user_birthday", "publish_actions"}, new DialogListener() {
@Override
public void onComplete(Bundle values) {}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
}
}
public void logoutFB(){
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
try{
json = Util.parseJson(facebook.request("me"));
Log.e("FacebookConnect", "JSON " + json.toString());
}catch (JSONException e) {
Log.e("FacebookConnect", "JSONException " + e.toString());
}catch(FacebookError fbe){
Log.e("FacebookConnect", "FacebookError " + fbe.toString());
}catch (Exception e){
Log.e("FacebookConnect", "Exception " + e.toString());
}
Intent a = new Intent(FacebookConnectActivity.this, FacebookDataProcess.class);
a.putExtra(TAG_JSON, json.toString());
startActivity(a);
finish();
}
}