1

I've been succeeded uploading a photo to Facebook via my Android app, which exists in the album created for my app, but the photo needs to be approved manually by the user, and Facebook said:

Would you like to add these photos to your album?
The photos below were uploaded from another application, you'll need to approve them.

It looks like this on Facebook:

enter image description here

By the way, I've added the user_photos permission. And here is the code for uploading:

public void uploadToFB(Uri photo){

    Session session = Session.getActiveSession();
    Bundle bundle = new Bundle(); 
    bundle.putString("url", "http://6269-9001.zippykid.netdna-cdn.com/wp-content/uploads/2013/09/Cute-Dog-Wallpaper-Pictures.jpg");          

    new Request(
        session,
        "/me/photos",
        bundle,
        HttpMethod.POST,
        new Request.Callback() {
            @Override
            public void onCompleted(Response response) {
                dialog.dismiss();

            }
        }
    ).executeAsync();

}

In the MainActivity:

@Override
protected void onResumeFragments() {
    super.onResumeFragments();
    Session session = Session.getActiveSession();

    if (session != null && session.isOpened()) {
        startActivity(new Intent(this, LoggedMainActivity.class));
    } else {
        showLoginFragment();            
    }
}

private void showLoginFragment(){
    LoginFragment login=new LoginFragment();
        getSupportFragmentManager()
        .beginTransaction()
        .add(android.R.id.content, login)
        .commit();
}

And this is the LoginFragment:

public class LoginFragment extends Fragment {

private LoginButton authButton;

@Override
public View onCreateView(LayoutInflater inflater, 
        ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.login_fragment, 
            container, false);
    authButton=(LoginButton)view.findViewById(R.id.login_button);
    authButton.setReadPermissions(Arrays.asList("user_photos","publish_stream","read_stream"));
    return view;
}

}
betteroutthanin
  • 7,148
  • 8
  • 29
  • 48

1 Answers1

1

You are missing the publish_stream permission on Your Facebook Login Widget

Here is a demonstration of how to add that permission:

/*LoginButton authButton = (LoginButton) findViewById(R.id.YOUR_ID);
authButton.setReadPermissions(Arrays.asList("user_photos"));
authButton.setPublishPermissions(Arrays.asList("publish_stream","read_stream"));*/

Just Add these permissions to your Login Widget and everything should work fine.

Edit:
Setting up Read and Publish Permissions together :
Get Read and Publish Permissions in one request

I hope this helps.

Community
  • 1
  • 1
Salman Khakwani
  • 6,684
  • 7
  • 33
  • 58
  • Hi, I got an error when adding permissions above, the error is: Cannot pass a publish or manage permission (publish_stream) to a request for read authorization. Any tips :) – betteroutthanin Jan 26 '14 at 13:40
  • Yes, i expected that :) You are having some conflicting permissions. Please post the initialization code of your Facebook Login Widget. – Salman Khakwani Jan 26 '14 at 13:42
  • Hi, another error appears: java.lang.RuntimeException: Unable to resume activity {com.example.android/com.example.android.MainActivity}: java.lang.UnsupportedOperationException: Cannot call setReadPermissions after setPublishPermissions has been called. – betteroutthanin Jan 26 '14 at 13:59
  • I found a useful link regarding this error, please check the updated answer. Thank You. – Salman Khakwani Jan 26 '14 at 14:12