4

dear friends, I am developing an application with Facebook integration on Android using the Facebook SDK. My application should just be able to post a link. I use this code:

this.req = new Request(session, "me/feed", b, HttpMethod.POST,
                    callback);

            RequestAsyncTask sendRequest = new RequestAsyncTask(req);
            sendRequest.execute();

Using this permission:

public static final List<String> PERMISSIONS = Arrays
            .asList("publish_actions" );

And actually it works fine posting links on my developer account. As soon as I take another account I get this error message:

(#200) The user hasn't authorized the application to perform this action

Can you please help me? Or just give a hint?

1 Answers1

0

I think your KeyHash that you've added on your Facebook account allow you to share some link. To be able to post some stuff on user wall, you have to respect this facebook "best practive": here is my production code, who works fine :

private void publishStory(String hash, String title, String user) {

    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(getActivity(), PERMISSIONS);
            session.requestNewPublishPermissions(newPermissionsRequest);
            return;
        }
        Bundle postParams = new Bundle();
        postParams.putString("name", title);
        postParams.putString("caption", "By Recommend Android");
        postParams.putString("description", user+" "+"STRONGLY recommends"+" "+title);
        postParams.putString("link", "http://re.co/"+hash);
        postParams.putString("picture", "http://re.co/assets/img/useful-exp.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) {
                    debug.print("erreur");
                } else {
                    debug.print("erreur2");
                }
            }
        };
        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;
}
Adrien Cerdan
  • 1,005
  • 1
  • 11
  • 21