0

The problem is that when I call the facebook dialog to post to my wall it doesn't recoginize the bundle params I put in. I believe the error is in this piece of code:

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

though, I'm not sure to why it doesn't recognize the bundle and put in the values. Instead it just brings up the dialog allowing the user to enter their own post and at the bottom it says "via appTesting".

If you could provide any help or information it would be greatly appreciated! Thanks

Here's the code:

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);
 }
2
  • You can not pre-populate the message for the Feed dialog any more.
    – CBroe
    Oct 2, 2012 at 12:54
  • So instead I would have to use request?
    – chRyNaN
    Oct 2, 2012 at 16:49

1 Answer 1

0

Why are you using fb.dialog() to post a status?

Instead of calling:

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

do:

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

to post to your wall.

EDIT:

I forgot that you can also have the user input their own message, which you can do in the fb.dialog(). I would look at our sample code to see how to do it properly which you can see here. Notice that there is no link param. Maybe try removing that to see if it displays your feed story properly.

4
  • I'm trying to allow the user to write a post but just have the extras from the bundle put their automatically. So, that's why I chose to use fb.dialog instead of mAsyncRunner.request. Though, to be honest after trying to use request I ran into the same problem as well. The link you sent me seems to use the same tactic I have (line 191). But instead it calls a customized listener that seems to do the same thing. I'm new to the facebook sdk and have been having obvious trouble with it, so, I've referred to tutorials such as link
    – chRyNaN
    Oct 1, 2012 at 23:09
  • I followed that tutorial almost precisely and yet his worked and mine didn't. So, thats the problem I'm having
    – chRyNaN
    Oct 1, 2012 at 23:11
  • is there any logcat error messages? Enable logging by setting Util.ENABLE_LOG to true in the facebook SDK code. Pasting any relevant stack trace or error messages you see can possibly help.
    – Jesse Chen
    Oct 2, 2012 at 18:32
  • I tried using the mAsyncRunner.request("me/feed", params, "POST", new RequestListener() { because I was told the dialog no longer supports predefined posts. Though, I ran into another error and I posted the code and logcat here question
    – chRyNaN
    Oct 3, 2012 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.