Kirit  Vaghela
Kirit Vaghela

Reputation: 12674

FeedDialog in android facebook sdk does not work

I'm trying to post a message on facebook using FeedDialog.
ref : http://developers.facebook.com/docs/howtos/androidsdk/3.0/feed-dialog/

Code:

private void publishFeedDialog(){

    Bundle params = new Bundle();
    params.putString("name", "Facebook SDK for Android");
    params.putString("caption", "Build great social apps and get more installs.");
    params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
    params.putString("link", "https://developers.facebook.com/android");
    params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");


    FeedDialogBuilder builder = new FeedDialogBuilder(getActivity(), Session.getActiveSession(), params);
    builder.setOnCompleteListener(new OnCompleteListener() {

        @Override
        public void onComplete(Bundle values, FacebookException error) {

            if (error != null) {
                Log.d(TAG, "FeedDialog Error : "+error.getMessage());
            }

            if (error == null) {

                // When the story is posted, echo the success
                // and the post Id.

                final String postId = values.getString("post_id");

                if (postId != null) {
                    Toast.makeText(getActivity(),"Posted story, id: "+postId,Toast.LENGTH_SHORT).show();
                } else {
                    // User clicked the Cancel button
                    Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled",Toast.LENGTH_SHORT).show();
                }
            } else if (error instanceof FacebookOperationCanceledException) {
                // User clicked the "x" button
                Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
            } else {
                // Generic, ex: network error
                Toast.makeText(getActivity().getApplicationContext(), "Error posting story",Toast.LENGTH_SHORT).show();
            }
        }
    });

    builder.build().show();

}

Button onClickListener:

publishButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            publishFeedDialog();

        }
    });

When I click on publish button, a waiting dialog is shown and it dismisses after some time and I got Toast saying that "Error posting story", why?

logcat

D/FacebookSDK.WebDialog(3572): Webview loading URL: 

https://m.facebook.com/dialog/feed?picture=https%3A%2F%2Fraw.github.com%2Ffbsamples%2Fios-3.x-howtos%2Fmaster%2FImages%2Fiossdk_logo.png&redirect_uri=fbconnect%3A%2F%2Fsuccess&description=The%20Facebook%20SDK%20for%20Android%20makes%20it%20easier%20and%20faster%20to%20develop%20Facebook%20integrated%20Android%20apps.&link=https%3A%2F%2Fdevelopers.facebook.com%2Fandroid&name=Facebook%20SDK%20for%20Android&display=touch&app_id=504782202896276&caption=Build%20great%20social%20apps%20and%20get%20more%20installs.&type=user_agent&access_token=BAAHLGMPkf5QBACk6Gon9Mkoxgt0RvmdI6DkStkZBs8wj9ZBGxuXSS0CoWnjZCTfqPY1bUb006uZAeoxCcj7SwSCm4UTnBbW0z7GBmI2cxvCoHEb2ZBrhLkZABUBcYKXld7giXXu498X1Piv5RbsZCGiILBu6oFSgiblctPNEHmYr4iSI6ZCfiMQJ449BMsxPULJegXaFFJWc2T9ScXVK160V9PU3kNlpPjpjbDQ3jiHjRwZDZD

When I open above link into browser it work and show "post to wall" dialog like enter image description here

D/MainFragment(3150): {Response:  responseCode: unknown, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false}

D/MainFragment(3150): FeedDialog Error : Couldn't find the URL.

Upvotes: 1

Views: 2548

Answers (1)

Shoshi
Shoshi

Reputation: 2254

this is from facebook developer page, i have used it . for my case it works. u should try this:

private void publishFeedDialog() {
    Bundle params = new Bundle();
    params.putString("name", "Facebook SDK for Android");
    params.putString("caption", "Build great social apps and get more installs.");
    params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
    params.putString("link", "https://developers.facebook.com/android");
    params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");

    WebDialog feedDialog = (
        new WebDialog.FeedDialogBuilder(getActivity(),
            Session.getActiveSession(),
            params))
        .setOnCompleteListener(new OnCompleteListener() {

            @Override
            public void onComplete(Bundle values,
                FacebookException error) {
                if (error == null) {
                    // When the story is posted, echo the success
                    // and the post Id.
                    final String postId = values.getString("post_id");
                    if (postId != null) {
                        Toast.makeText(getActivity(),
                            "Posted story, id: "+postId,
                            Toast.LENGTH_SHORT).show();
                    } else {
                        // User clicked the Cancel button
                        Toast.makeText(getActivity().getApplicationContext(), 
                            "Publish cancelled", 
                            Toast.LENGTH_SHORT).show();
                    }
                } else if (error instanceof FacebookOperationCanceledException) {
                    // User clicked the "x" button
                    Toast.makeText(getActivity().getApplicationContext(), 
                        "Publish cancelled", 
                        Toast.LENGTH_SHORT).show();
                } else {
                    // Generic, ex: network error
                    Toast.makeText(getActivity().getApplicationContext(), 
                        "Error posting story", 
                        Toast.LENGTH_SHORT).show();
                }
            }

        })
        .build();
    feedDialog.show();
}

closely look at this part:

WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(getActivity(),

but u have used

FeedDialogBuilder builder = new FeedDialogBuilder(getActivity(),

i think the problem is here.

Upvotes: 1

Related Questions