2013-07-09 76 views
4

親愛的朋友, 我正在開發一個應用程序,使用Facebook SDK在Android上進行Facebook集成。我的應用程序應該能夠發佈鏈接。我用這個代碼:錯誤#200 Facebook SDK Android

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

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

使用這個權限:

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

而實際上它的作品在我的開發人員帳戶精細發佈鏈接。只要我拿另一個帳戶,我收到以下錯誤消息:

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

你能幫我嗎?或者只是提示一下?

+0

嘗試添加'status_update'權限。已經嘗試過 –

+0

.;) –

回答

0

我認爲你在Facebook賬戶中添加的KeyHash可以讓你分享一些鏈接。爲了能夠在用戶牆上張貼一些東西,你必須尊重這個Facebook的「最佳實踐」:這裏是我的產品代碼,誰工作得很好:

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; 
}