问题是,当我调用 facebook 对话框发布到我的墙上时,它无法识别我放入的捆绑参数。我相信错误出在这段代码中:
fb.dialog(AppTestingActivity.this, "feed" , params, new DialogListener() {
不过,我不确定为什么它不能识别捆绑包并输入值。相反,它只是弹出对话框,允许用户输入他们自己的帖子,并在底部显示“通过 appTesting”。
如果您能提供任何帮助或信息,将不胜感激!谢谢
这是代码:
package com.app.apptesting;
import java.io.IOException;
import java.net.MalformedURLException;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class AppTestingActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
public String APP_ID = "App ID Was Entered Here"; //removed app id just for question
public Facebook fb = new Facebook(APP_ID);
ImageView pic, button;
Button post;
SharedPreferences sp;
public String access_token;
public long expires;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
post = (Button)findViewById(R.id.button1);
sp = getPreferences(MODE_PRIVATE);
access_token = sp.getString("access_token", null);
expires = sp.getLong("access_expires", 0);
rememberLogin();
button = (ImageView)findViewById(R.id.login);
pic = (ImageView)findViewById(R.id.picture_pic);
button.setOnClickListener(this);
updateButtonImage();
}
public void rememberLogin(){
if (access_token != null){
fb.setAccessToken(access_token);
}
if (expires != 0){
fb.setAccessExpires(expires);
}
}
private void updateButtonImage() {
// TODO Auto-generated method stub
if (fb.isSessionValid()){
post.setVisibility(Button.VISIBLE);
button.setImageResource(R.drawable.logout_button);
}else{
post.setVisibility(Button.INVISIBLE);
button.setImageResource(R.drawable.login_button);
}
}
public void buttonClicks(View v){
switch (v.getId()){
case R.id.button1:
//post to facebook
Bundle params = new Bundle();
params.putString("name", "AppTesting");
params.putString("caption", "Just Testing");
params.putString("description", "Trying to work with the Facebook SDK");
params.putString("link", "");
params.putString("picture", "");
fb.dialog(AppTestingActivity.this, "feed" , params, new DialogListener() {
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
}
public void onCancel() {
// TODO Auto-generated method stub
}
});
break;
}
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (fb.isSessionValid()){
//logout
try {
fb.logout(getApplicationContext());
updateButtonImage();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
//login
fb.authorize(AppTestingActivity.this, new String[]{"publish_stream", "email"}, Facebook.FORCE_DIALOG_AUTH, new DialogListener() {
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "onFacebookError", Toast.LENGTH_SHORT).show();
}
public void onError(DialogError e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "onError", Toast.LENGTH_SHORT).show();
}
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
Editor editor = sp.edit();
editor.putString("access_token", fb.getAccessToken());
editor.putLong("access_expires", fb.getAccessExpires());
editor.commit();
updateButtonImage();
}
public void onCancel() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "onCancel", Toast.LENGTH_SHORT).show();
}
});
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
fb.authorizeCallback(requestCode, resultCode, data);
}