2014-10-08 34 views
1

需要發佈狀態消息,或者用戶是否在facebook上使用該狀態消息選擇了一個圖像而不使用對話框。facebook post image /文字使用圖形api錯誤

final Session sessionfb = ParseFacebookUtils.getSession(); 

    List<String> permissions = sessionfb.getPermissions(); 
    if (!permissions.contains("publish_actions")) { 

     Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
       FlyTags.this, Arrays.asList("publish_actions")) 
       .setCallback(newPermissionsCallback).setRequestCode(1); 
      sessionfb.requestNewPublishPermissions(newPermissionsRequest); 

    } 
    else { 

     Bundle parameters = new Bundle(); 
     parameters.putString("message", mfinalmsg); 
     parameters.putString("description", "test"); 

     if (imgdata != null) { 

      parameters.putByteArray("picture", imgdata); 
         } 
     new Request(sessionfb, "me/photos/feed", parameters, HttpMethod.POST, 
       new Request.Callback() { 
        public void onCompleted(Response response) { 

         Debug.e("facebook post response", 
           response.toString()); 
        } 
       }).executeAsync(); 

響應:

{Response: responseCode: 500, graphObject: null, error: {HttpStatus: 500, errorCode: 100, errorType: FacebookApiException, errorMessage: Invalid parameter}, isFromCache:false} 

回答

0

使用我/飼料如果狀態包含。如果連接一個圖像使用我/照片。你應該有一個發佈許可文本。

String graphapimethod = "me/feed"; 
    Bundle parameters = new Bundle(); 
    parameters.putString("message", mfinalmsg); 
    parameters.putString("description", "testhashmash"); 

    if (imgdata != null) { 

     graphapimethod = "me/photos"; 
     parameters.putByteArray("picture", imgdata); 

    } 
    // "me/feed" 
    new Request(session, graphapimethod, parameters, HttpMethod.POST, 
      new Request.Callback() { 
       public void onCompleted(Response response) { 
        /* handle the result */ 

        if (response.getError() == null) { 
         Toast.makeText(FlyTags.this, "Posted succeffully.", 
           Toast.LENGTH_SHORT).show(); 
         dialog.dismiss(); 

        } 

        else { 

         Toast.makeText(FlyTags.this, 
           "oops..please try again", 
           Toast.LENGTH_SHORT).show(); 
        } 

        Debug.e("facebook post response", response.toString()); 
       } 
      }).executeAsync();