我已经在图表api中的Facebook页面成功发布了一个Feed。
try {
resObj.put("message","feed from android");
//resObj.put("object_attachment",bitmap);
} catch (JSONException e) {
e.printStackTrace();
}
GraphRequest request = GraphRequest.newPostRequest(
AccessToken.getCurrentAccessToken(),"363453267193844/photos",resObj,
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
Log.i(TAG,"post page response::"+graphResponse);
}
}
);
request.executeAsync();
但是,我无法将图片发布到脸谱页面。问题是我无法在Graph Api中发布的Json数据中找到图像附件的密钥。
来自facebook的失败回复是
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 324, errorType: OAuthException, errorMessage: (#324) Requires upload file}}
答案 0 :(得分:2)
最后,最后,我能够将图像发布到Facebook页面。这就是我发布照片的方式。
Bundle bundle=new Bundle();
bundle.putByteArray("object_attachment",byteArray);// object attachment must be either byteArray or bitmap image
bundle.putString("message","some message here");
GraphRequest graphRequest=new GraphRequest(AccessToken.getCurrentAccessToken(),
"{page_id}/photos",
bundle,
HttpMethod.POST,
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
Log.i("post page response::" + graphResponse);
}
);
graphRequest.executeAsync();
答案 1 :(得分:0)
1。)确保您拥有publish_pages
权限的页面访问令牌,可用于发布新照片。
2。)来自docs。请注意,您在通话中的pageid之前没有“/”。
将照片发布到Facebook有两种不同的方式:
1:将照片作为multipart / form-data附加。对象的名称 没关系,但从历史上看,人们已经将源作为 照片的参数名称。这是如何工作取决于您的SDK 碰巧用来做帖子。
2:使用以下内容发布,使用互联网上已有的照片 url参数:
Bundle params = new Bundle(); params.putString("url", "{image-url}"); /* make the API call */ new Request( session, "/{page-id}/photos", params, HttpMethod.POST, new Request.Callback() { public void onCompleted(Response response) { /* handle the result */ } } ).executeAsync();
无法在同一图表API中发布多张照片 调用
3。)示例==>
尝试这样,即发布照片的byteArrayStream
postParams = new Bundle();
postParams.putString("message", "feed from android");
postParams.putBoolean("published",true);
String pageID = "363453267193844";
//Post to the page as the page user
ByteArrayOutputStream stream = new ByteArrayOutputStream();
<YOURBITMAPPHOTOHANDLE>.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
postParams.putByteArray("source", byteArray);
postParams.putString("access_token", "your_page_access_token");
/* make the API call */
new Request(
sessionInstance,
"/" + pageID + "/photos",
postParams,
HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
//An error occurred during posting to facebook
FacebookRequestError error = response.getError();
if (error != null) {
isPostingError = true;
postingErrorMessage = error.getErrorUserMessage();
} else {
isPostingError = false;
}
}
}
). executeAsync();