Sharing wall posts on facebook android sdk

Hi, I am new to Android programming. I want to share an image with some description on facebook. I tried to explain each method in answers to stackoverflow. My problem is to open the facebook dialog, but it does not have the package options set. Please help me with this. I have already tried almost 20 different pieces of code. Please give me a fully functional code.

    @Override
        public void onClick(View v) {
            fb = new Facebook(app_id);
            Bundle par = new Bundle();
            par.putString("name", "Ass");
            fb.dialog(con,"feed",par, new DialogListener(){

                @Override
                public void onCancel() {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onComplete(Bundle arg0) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onError(DialogError arg0) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onFacebookError(FacebookError arg0) {
                    // TODO Auto-generated method stub

                }});


        }
    });

}
+4
source share
1 answer

facebook ? , facebook, api / authtoken.

( 5 fb) , facebook . , , ..... , .

;

loginButton sdk? :

<com.facebook.widget.LoginButton
    android:id="@+id/authButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="30dp"
    />

facebook, facebook, ( onStatusChange). , .

, , .

, tho, facebook api android , - .

< < < < < < EDIT: → → →

, (session.getActiveSession() == Session.OPENED, ), - , . facebook, ( publishStory() ):

private void publishStory() {
Session session = Session.getActiveSession();

if (session != null){

    // Check for publish permissions    
    List<String> permissions = session.getPermissions();
    if (!isSubsetOf(PERMISSIONS, permissions)) {
        pendingPublishReauthorization = true;
        Session.NewPermissionsRequest newPermissionsRequest = new Session
                .NewPermissionsRequest(this, PERMISSIONS);
    session.requestNewPublishPermissions(newPermissionsRequest);
        return;
    }

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

    Request.Callback callback= new Request.Callback() {
        public void onCompleted(Response response) {
            JSONObject graphResponse = response
                                       .getGraphObject()
                                       .getInnerJSONObject();
            String postId = null;
            try {
                postId = graphResponse.getString("id");
            } catch (JSONException e) {
                Log.i(TAG,
                    "JSON error "+ e.getMessage());
            }
            FacebookRequestError error = response.getError();
            if (error != null) {
                Toast.makeText(getActivity()
                     .getApplicationContext(),
                     error.getErrorMessage(),
                     Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getActivity()
                         .getApplicationContext(), 
                         postId,
                         Toast.LENGTH_LONG).show();
            }
        }
    };

    Request request = new Request(session, "me/feed", postParams, 
                          HttpMethod.POST, callback);

    RequestAsyncTask task = new RequestAsyncTask(request);
    task.execute();
}


private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
    for (String string : subset) {
        if (!superset.contains(string)) {
            return false;
        }
    }
    return true;
}

POST , . , . , RequestAsyncTask .

, , facebook ( ), , ( ), , , "me/feed" , .

, , , , - ..

, .

+3

All Articles