2014-06-25 13 views
0

我一直在試圖創建一個解決方案,共享一個位圖圖像,特別是一個屏幕截圖。我一直在關注這個解決方案 - >How to post Bitmap to facebook using facebook sdk?使用Facebook SDK 3.15。如何共享位圖

因此,這是我的代碼,

@SuppressWarnings("deprecation") 
    private void shareToFacebook(Bitmap img) { 

     if (img != null) { 

      Request request = Request.newUploadPhotoRequest(Session.getActiveSession(), img, uploadPhotoRequestCallback); 
      Bundle parameters = request.getParameters(); // <-- THIS IS IMPORTANT 
      parameters.putString("DriveSync Telematics", "Wow look at my Score!"); 
      // add more params here 
      request.setParameters(parameters); 
      request.executeAsync(); 
     } 
    } 

隨着回調是

Request.Callback uploadPhotoRequestCallback = new Request.Callback() { 
     @Override 
     public void onCompleted(Response response) { 
      if (response.getError() != null) { 
       //post error 
      } else{ 
       String idRploadResponse = (String) response.getGraphObject().getProperty("id"); 
       if (idRploadResponse!= null) { 

        String fbPhotoAddress = "https://www.facebook.com/photo.php?fbid=" +idRploadResponse; 
       } else { 
        Log.d(TAG, "Facebook upload failed"); 
       } 
      } 
     } 
    }; 

而且我收到此錯誤

 java.lang.IllegalArgumentException: A property named "My Score" was not found on the action. The name of the preview property must match the name of an action property. 

有誰知道這意味着什麼/我如何解決我的問題。

感謝,

彼得,

+0

有一個新的相關問題http://stackoverflow.com/問題/ 24417668/error-when-using-facebookdialog-photosharedialogbuilder –

回答

0
parameters.putString("DriveSync Telematics", "Wow look at my Score!"); 

^^此行是問題。您實質上是在告訴設置「DriveSync Telematics」字段的值爲「Wow ...」的請求。但是/ me/photos圖形API端點中沒有「DriveSync Telematics」字段。

下面是用戶/照片圖形API端點的文檔:https://developers.facebook.com/docs/graph-api/reference/v2.0/user/photos/#publish

可能是你想要做的是一樣的東西:

parameters.putString("message", "Wow look at my Score!"); 
+0

擺脫了錯誤,但沒有facebook對話框打開用戶張貼圖片。爲什麼是這樣。 –

+0

您使用的方法不會彈出對話框,它使用圖形API直接發佈到Facebook(如果您有發佈權限)。如果你想使用共享對話框,你應該使用FacebookDialog.PhotoShareDialogBu​​ilder類https://developers.facebook.com/docs/reference/android/current/class/FacebookDialog.PhotoShareDialogBu​​ilder/ –

+0

好的,但PhotoShareDialog只允許我使用只接受鏈接而不是位圖圖像的.setPicture。我如何解決這個問題。 –

相關問題