0

问题是,当我调用 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);
 }
4

1 回答 1

0

你为什么fb.dialog()要发布状态?

而不是调用:

fb.dialog(AppTestingActivity.this, "feed" , params, new DialogListener() {

做:

mAsyncRunner.request("me/feed", params, "POST", new RequestListener() {

张贴到你的墙上。

编辑:

我忘了你也可以让用户输入他们自己的消息,你可以在 fb.dialog() 中完成。我会查看我们的示例代码以了解如何正确执行此操作,您可以在此处查看。请注意,没有link参数。也许尝试删除它以查看它是否正确显示您的提要故事。

于 2012-10-01T22:17:12.013 回答