我正在使用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;
你能把結果字符串放在* relativePath *裏嗎?另外,根據文檔,您可以將標籤發佈到* PHOTO_ID/tags/USER_ID *或* PHOTO_ID/tags?到= USER_ID *。你以後也嘗試過嗎? – 2012-04-05 09:44:32
我只是嘗試了後來沒有運氣。並且relativePath更改應用程序的每個運行,應用程序圖片在拍攝新照片後上傳並標記。下面是我最近使用的relativePath的一個例子: 100003703122664_62586/tags/100003702982567 – justbaum30 2012-04-05 13:27:34
您確定此照片的ID是否正確?這看起來不正確。你如何得到照片的ID?也就是說,* Constants.photoID *來自哪裏? – 2012-04-05 13:48:08