2012-04-05 38 views
0

我正在使用Facebook應用程序,並且正在嘗試讓我的應用程序標記其中一位用戶的朋友。我幾乎讓它工作100%,除了當它應該是標記人,我反而得到一個錯誤信息如下:Android Facebook不受支持的發佈請求錯誤

{「error」:{「message」:「不支持的post請求」,「鍵入「:」GraphMethodException「,」code「:100}}

用戶和照片ID肯定是正確的,這不是問題。否則,我不知道還有什麼可能導致此錯誤。代碼如下,供參考。非常感謝!

public void setTag() { 
    String relativePath = Constants.photoID + "/tags/" + Constants.userID; 
    Bundle params = new Bundle(); 
    params.putString("x", "5"); 
    params.putString("y", "5"); 
    Constants.mAsyncRunner.request(relativePath, params, "POST", new TagPhotoRequestListener(), 
      null); 
} 



public class TagPhotoRequestListener extends BaseRequestListener { 

@Override 
public void onComplete(final String response, final Object state) { 
    if (response.equals("true")) 
    { 
     String message = "User tagged in photo at (5, 5)" + "\n"; 
     message += "Api Response: " + response; 
     Log.i("TagPhotoRequestListener", message); 
    } 
    else 
    { 
     Log.w("TagPhotoRequestListener", "User could not be tagged."); 
    } 
} 

public void onFacebookError(FacebookError e) { 
    Log.w("TagPhotoRequestListener", "Facebook Error: " + e.getMessage()); 
} 

}

編輯:這裏是我的圖片的發佈和獲取PHOTOID代碼。出於測試目的,它只是我SD卡上的一張照片。

public void postPhoto() { 
    byte[] data = null; 

    Bitmap bi = BitmapFactory.decodeFile("/mnt/sdcard/Download/KathleenSchedule.jpg"); 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
    data = baos.toByteArray(); 

    Bundle params = new Bundle(); 
    params.putString(Facebook.TOKEN, Constants.mFacebook.getAccessToken()); 
    params.putString("method", "photos.upload"); 
    params.putByteArray("picture", data); 

    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(Constants.mFacebook); 
    mAsyncRunner.request(null, params, "POST", new PhotoUploadListener(), null); 
} 


public class PhotoUploadListener extends BaseRequestListener { 

@Override 
public void onComplete(final String response, final Object state) { 
    try { 
     // process the response here: (executed in background thread) 
     Log.d("PhotoUploadListener", "Response: " + response.toString()); 
     JSONObject json = Util.parseJson(response); 
     System.out.println(response); 
     final String photo_id = json.getString("pid"); 
     Constants.photoID = photo_id; 
+0

你能把結果字符串放在* relativePath *裏​​嗎?另外,根據文檔,您可以將標籤發佈到* PHOTO_ID/tags/USER_ID *或* PHOTO_ID/tags?到= USER_ID *。你以後也嘗試過嗎? – 2012-04-05 09:44:32

+0

我只是嘗試了後來沒有運氣。並且relativePath更改應用程序的每個運行,應用程序圖片在拍攝新照片後上傳並標記。下面是我最近使用的relativePath的一個例子: 100003703122664_62586/tags/100003702982567 – justbaum30 2012-04-05 13:27:34

+0

您確定此照片的ID是否正確?這看起來不正確。你如何得到照片的ID?也就是說,* Constants.photoID *來自哪裏? – 2012-04-05 13:48:08

回答

0

好的,現在你的問題已經很清楚了。

您正在使用photos.upload方法,其棄用:

我們在自嘲的REST API的過程中,所以如果你是 建立一個新的應用程序,你不應該使用這個功能。相反 因爲你使用的是老辦法,你要老響應類型使用Graph API和POST到的User object

照片連接。 切換到使用圖形API方式,你應該得到的照片ID在響應。

+0

啊,我明白了。我原以爲我在使用Graph API。在我看來,他們的Android文檔相當糟糕。我將不得不看看Graph API方法是什麼。謝謝。 – justbaum30 2012-04-05 14:34:16

+0

我想你錯過了一些東西......圖表api與android無關,它是基於url(http請求)的api,您可以以任何您想要的方式訪問它。 android sdk(非常像js或php)爲你提供http請求。有關圖api的文檔,請查看Graph Api文檔,而不是Android SDK文檔。 – 2012-04-05 14:36:02

+0

好吧,我會檢查出來,再次感謝芽。 – justbaum30 2012-04-05 14:45:34

相關問題