dancingbush
dancingbush

Reputation: 2281

Facebook Share session not open error

I am using the Facebook SDK to upload data from a app to the users Facebook wall.

I have implemented code to allow a user to share data via a dialog box or if user has no android FB app to post directly on wall, went through tutorial https://developers.facebook.com/docs/android/share .

I am getting the following error:

Failed to find provider info for com.facebook.katana.provider.PlatformProvider

02-19 18:49:28.405: E/AndroidRuntime(12847): FATAL EXCEPTION: main
02-19 18:49:28.405: E/AndroidRuntime(12847): com.facebook.FacebookException: Attempted to use a Session that was not open.
02-19 18:49:28.405: E/AndroidRuntime(12847):    at com.facebook.widget.WebDialog$BuilderBase.<init>(WebDialog.java:463)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at com.facebook.widget.WebDialog$FeedDialogBuilder.<init>(WebDialog.java:626)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at com.mooney.diveapp.LogDive.publishFeedDialog(LogDive.java:437)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at com.mooney.diveapp.LogDive.onClick(LogDive.java:361)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at android.view.View.performClick(View.java:4377)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at android.view.View$PerformClick.run(View.java:18044)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at android.os.Handler.handleCallback(Handler.java:725)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at android.os.Looper.loop(Looper.java:137)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at android.app.ActivityThread.main(ActivityThread.java:5306)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at java.lang.reflect.Method.invokeNative(Native Method)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at java.lang.reflect.Method.invoke(Method.java:511)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
02-19 18:49:28.405: E/AndroidRuntime(12847):    at dalvik.system.NativeStart.main(Native Method)

Code is:

private UiLifecycleHelper uiHelper;//FB call back class instance
    private StatusCallback callback;


//onCreate - FB object to handle dialog callbacks
                uiHelper = new UiLifecycleHelper(this, callback);
                uiHelper.onCreate(savedInstanceState);


//call face book dialog to share data from dive
            //check first if user has android FB app, if not cant use dialog andmust use feed instead
            if (FacebookDialog.canPresentShareDialog(getApplicationContext(), 
                    FacebookDialog.ShareDialogFeature.SHARE_DIALOG)){
            FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
            .setLink("https://developers.facebook.com/android")
            .setRequestCode(4)
            .setApplicationName("Dive App")
            .setName(diveSiteString)
            .setDescription(this.bottomDiveTime+" minute dive at "+ this.waterTemperature +
                    "degrees celcuis, vizibilty "+this.viz+ "depth:  "
                    +this.diveDepth+". I rate this dive a "+this.diveRate+"/5!")
                    .setPlace(this.diveLoctionString)
            .build();

            uiHelper.trackPendingDialogCall(shareDialog.present());
            }else{
                //publish the post using the feed dialog
                publishFeedDialog();

            }



private void publishFeedDialog() {
        /* if cant use share dialog as user dos not haveFB android app
        *use a web dialog to post the feed
        */
        Bundle params = new Bundle();
        params.putString("name", "Dive App");
        params.putString("caption", "Dive site "+this.diveSiteString+" at "+this.diveLoctionString);
        params.putString("description", this.bottomDiveTime+" minute dive at "+ this.waterTemperature +
                    "degrees celcuis, vizibilty "+this.viz+ "depth:  "
                    +this.diveDepth+". I rate this dive a "+this.diveRate+"/5!");
        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(getBaseContext(),
                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(getBaseContext(),
                                "Posted story, id: "+postId,
                                Toast.LENGTH_SHORT).show();
                        } else {
                            // User clicked the Cancel button
                            Toast.makeText(getBaseContext().getApplicationContext(), 
                                "Publish cancelled", 
                                Toast.LENGTH_SHORT).show();
                        }
                    } else if (error instanceof FacebookOperationCanceledException) {
                        // User clicked the "x" button
                        Toast.makeText(getBaseContext().getApplicationContext(), 
                            "Publish cancelled", 
                            Toast.LENGTH_SHORT).show();
                    } else {
                        // Generic, ex: network error
                        Toast.makeText(getBaseContext().getApplicationContext(), 
                            "Error posting story", 
                            Toast.LENGTH_SHORT).show();
                    }
                }



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

    }//end publishFeedDialog

//onActivity result method for FB callback
protected void onActivityResult(int requestCode, int resultCode,
            final Intent data) {
        // method checks data returned form camera via startActivityForResult
        super.onActivityResult(requestCode, resultCode, data);
        // check data integrity against static int from activity class


        if(requestCode==4){
            //if req code = 4 the face book dialog call back 
            //configure a callback handler when FB share dialog closes and control returns to app

            uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
                    @Override
                    public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
                        Log.e("Activity", String.format("Error: %s", error.toString()));
                    }

                    @Override
                    public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
                        Log.i("Activity", "Success!");
                    }
                });

        }

Upvotes: 2

Views: 3068

Answers (2)

dancingbush
dancingbush

Reputation: 2281

OK so followed the share tutorial on FB, but didn't not include the log in session process as was not clear on tutorial.

Also allot of tutorials on-line are outdated (FB SDK ver <3.6).

So For those like me starting out this is a very good tutorial for implementing latest version 3.6 Dec 10th 2103 FB SDK:

http://code2care.org/pages/android-facebook-sdk-3.6-tutorial-integration-with-your-app/

Hope someone finds useful.

Upvotes: 3

Madhur Ahuja
Madhur Ahuja

Reputation: 22701

you must define your applicationId in the AndroidManifest.xml like this:

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>

under <application android:label="@string/app_name".... tag

where app_id is a string within your strings.xml.

Upvotes: 1

Related Questions