Facebook Graph API将本地图像上传到墙壁(Objective-C) [英] Facebook Graph API Upload Local Image to Wall (Objective-C)

查看:88
本文介绍了Facebook Graph API将本地图像上传到墙壁(Objective-C)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将本地的用户创建的照片从我的应用程序上传到用户的Facebook墙。我正在Objective-C开发一个应用程序,并使用PhFacebook图书馆与社交网络进行交互,但是我认为我的问题更可能来自于我与Facebook的实际交互的有缺陷的使用。

I'm trying to upload a local, user created photo from my application to the user's Facebook Wall. I'm developing an app in Objective-C and using the PhFacebook library to interact with the social network, but I think it's more likely my problem is coming from my flawed use of the actual interaction with Facebook.

确实,要在获得访问令牌之后将状态上传到用户的个人资料,该代码工作得很好:

Indeed, to upload a status to the user's profile, after having gotten an access token, this code works perfectly well:

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:1];

[variables setObject:@"This is a test." forKey:@"message"];

[fb sendRequest:@"me/feed" params:variables usePostRequest:YES];

但是,如果我尝试将照片直接上传到 me / feed ,使用以下代码,系统地失败,因为图像未显示,周围的文本是:

However, if I attempt to upload a photo directly to the me/feed, using the following code, it fails systematically, as the image isn't shown and the surrounding text is:

NSString *path = @"some/path/to/some/image/on/my/computer";

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];

[variables setObject:@"This is a test." forKey:@"message"];

[variables setObject:path forKey:@"source"];

[fb sendRequest:@"me/feed" params:variables usePostRequest:YES];

我尝试修改键到图像照片图片文件数据,但不能看到任何更改,而似乎作为最正确的。

I've tried modifying the source key to image, photo, picture, file, and data, but no changes could be seen, and source seems to be the most correct.

阅读有关上传照片的文档后: http://developers.facebook.com/docs/reference/api/photo/ ,我了解源参数对应一个URL。我已经尝试直接在用户的计算机上上传图像的数据或图像的本地路径,但是我还没有找到一种方法可以上传还没有上网的图像。我相信有一种方法可以做到这一点,即使是上传这个词意味着图像应该是本地的!

After having read the documentation about uploading photos: http://developers.facebook.com/docs/reference/api/photo/, I've understood that the source parameter corresponds to a URL. I've tried directly uploading the image's data or the image's local path on the user's computer, but I still haven't found a way to upload an image that isn't already on Internet. I'm sure there's a way to do this, even the word upload implies that the image should be local !

从本质上说,我似乎与此相反问题:使用Facebook的Graph API通过网址上传托管图像?

Essentially, it seems I'm having the opposite of this problem: Upload a hosted image with Facebook's Graph API by url?.

提前感谢任何可以帮助的人,我的Facebook朋友们开始对所有这些测试消息感到困惑:)

Thanks in advance to anyone who can help, my Facebook friends are starting to be puzzled over all these test messages :)

推荐答案

原来,只能使用PhFacebook来更简单的请求。这是我不得不将Facebook上的本地图像上传到Facebook Wall,而不使用PhFacebook,并在Mac上:

Turns out, you can only use PhFacebook for simpler requests. Here is what I had to do upload a local image to the Facebook Wall, without using PhFacebook, and on a Mac:

- 获取一个Facebook访问令牌与 publish_stream 使用WebView和ASIHTTPRequest设置权限(http://www.capturetheconversation.com/technology/iphone-facebook-oauth2-graph-api)。

-Get a Facebook Access Token with the publish_stream permission set using a WebView and ASIHTTPRequest (http://www.capturetheconversation.com/technology/iphone-facebook-oauth2-graph-api).

- 使一个简单的ASIHTTPRequest实际上传图像:

-Make a simple ASIHTTPRequest to actually upload the image:

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/me/photos?access_token=%@", access_token]];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

    [request addFile:@"/path/tolocalimage/" forKey:@"file"];

    [request setPostValue:[NSString stringWithFormat:@"This is a test."] forKey:@"message"];

    [request startAsynchronous];

还有你去!这个解决方案似乎比使用现有的框架更简单!唯一耗费时间的部分是构建WebView界面,但您可以从我发布的链接和PhFacebook.h中启发自己,PhFacebook.h使用类似(但略有不同)的技术。

And there you go ! This solution almost seems simpler than using existing frameworks ! The only time-consuming part is building the WebView interface, but you can simply inspire yourself from the link I posted and PhFacebook.h, which uses a similar (yet slightly different) technique.

这篇关于Facebook Graph API将本地图像上传到墙壁(Objective-C)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆