【发布时间】:2013-06-02 15:56:39
【问题描述】:
似乎没有明确的参考。 我正在创建一个用户可以登录 FB 的 Android 应用。
我关注了this tutorial on FB site,它给出了一个从 Web URL 发布图片的示例: postParams.putString("图片", "https:// 图片 URL");
但是,我想将我的项目中的本地 PNG 图像上传到登录用户的时间轴,该图像位于所有可重新绘制的文件夹中。
这是我的代码:
void publishStory()
{
Session session = Session.getActiveSession();
if (session != null)
{
Bundle postParams = new Bundle();
postParams.putString("name", "Name here.");
postParams.putString("caption", "Caption here.");
postParams.putString("description", "Description here.");
postParams.putString("link", "https://developers.facebook.com/android");
byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Bitmap bi = BitmapFactory.decodeResource(getResources(),R.drawable.logonew);
bi.compress(Bitmap.CompressFormat.PNG, 100, baos);
data = baos.toByteArray();
postParams.putString("method", "photos.upload");
postParams.putByteArray("picture", data);
Request.Callback callback = new Request.Callback()
{
public void onCompleted(Response response)
{
FacebookRequestError error = response.getError();
if (error != null)
Toast.makeText(_context , error.getErrorMessage(), Toast.LENGTH_SHORT).show();
else
Toast.makeText(_context, "Posted successful on your wall", Toast.LENGTH_SHORT).show();
}
};
Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
}
我能找到的所有例子都是处理 Facebook 类实例和 AsyncFacebookRunner 的郁闷。
此外,我从请求中得到的错误响应是: HttpStatus:400,errorCode:100,errorType:GraphMethodException,errorMessage:不支持的方法,photos.upload
那么,photos.upload 替代品是什么?请告知,一个代码示例会很棒,tnx。
【问题讨论】:
-
你看到我提供的答案了吗?如果它对你有用,你会接受它会很好。