Question

I want to post on friends wall and encountered difficulties.

First i uploaded the photo on my wall:

Request.Callback requestCallback = new Request.Callback() {
                            @Override
                            public void onCompleted(Response response) {
                                if (response.getError() != null) {
                                    Log.d("exception","error");
                                }

                                Object graphResponse = response.getGraphObject().getProperty("id");
                                if (graphResponse == null || !(graphResponse instanceof String)) {
                                    Log.d("exception","not upload image");
                                } else {
                                    String fbPhotoAddress = "https://www.facebook.com/photo.php?fbid=" +graphResponse;
                                    Log.d("exception","fb="+fbPhotoAddress);
                                }
                            }
                        };

                        try {
                            Request request = Request.newUploadPhotoRequest(Session.getActiveSession(), image, requestCallback);
                            request.executeAsync();
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }

I don't know how this link (fbPhotoAddress) will be used. I read about feed dialog, it take photo post in 200x200px.

How can i do this?

Was it helpful?

Solution

If you do not need to use facebook sdk, you can use code like the following:

        Intent share = new Intent(android.content.Intent.ACTION_SEND);
    share.setType("image/png"); 
    // gets the list of intents that can be loaded.
    List<ResolveInfo> resInfo = activity.getPackageManager().queryIntentActivities(share, 0);
    if (!resInfo.isEmpty()){
        for (ResolveInfo info : resInfo) {
            if (info.activityInfo.packageName.toLowerCase().contains("facebook") || 
                    info.activityInfo.name.toLowerCase().contains(type) ) {
                share.putExtra(Intent.EXTRA_SUBJECT,  subject);
                share.putExtra(Intent.EXTRA_TEXT, text);
                share.setPackage(info.activityInfo.packageName);
                share.putExtra(Intent.EXTRA_STREAM, imageUri);
                found = true;
                break;
            }
        }
        if (!found){
            Toast.makeText(activity, type+" is not installed on the device", Toast.LENGTH_SHORT).show();
            return;
        }
        activity.startActivity(Intent.createChooser(share, "Select"));

but if you are using facebook sdk, you can use FacebookDialog like the following but you need to integrate with facebook so read about it:

     FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(activity)
    .setLink(link)
    .setApplicationName(AppConstants.FACEBOOK_DISPLAY_APP_NAME)
    .setPicture(pictureUrl)
    .setName(subject)
    //.setDescription(text)
    .build();

You need to ask your self also why you added this photo to your facebook account, If you made this because you do not have URL for your photo (local photo) then it will not work using the facebook url because this URL is not public. If you test it, you will find this url will view your facebook page with the photo so you need to upload your photo on any server like AWS for example then using the photo url, you can make the sharing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top