本文介绍了使用iOS SDK将照片发布到Facebook粉丝专页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将照片上传到使用iOS SDK和图形API的自己的Facebook页面。我已经能够将照片上传到我自己的墙上。我也可以在我的粉丝页面墙上发布一条消息,作为管理员,并在我的粉丝页面上创建一个专辑,所以我认为我正在打电话,但没有成功。



这是我目前正在做的。



我正在使用

  Facebook * fb = [[Facebook alloc] init]; 
self.facebook = fb;
[fb release];
NSArray * permissions = [[NSArray arrayWithObjects:@read_stream,@offline_access,@publish_stream,@manage_pages,@user_photos,@friends_photos,nil] retain]
[facebook authorize:FB_APP_ID permissions:permissions delegate:self];
[权限释放];

登录后,我要求帐户

  [facebook requestWithGraphPath:@/ me / accountsandDelegate:self]; 

帐户将返回给我,每个页面的应用程序和我拥有的访问令牌。我使用一个简单的循环来解析帐户,以增加我希望上传照片的页面的access_token。



然后我设置我的Facebook的访问令牌反对新的access_token。

  facebook.accessToken = new_accessToken; 

,并尝试使用


$ b $上传照片我的粉丝专页b

  UIImage * uploadImage = [UIImage imageNamed:@t200.jpg]; 
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
uploadImage,@source,
@test caption,@message,
nil];


[facebook requestWithGraphPath:@/ me / photosandParams:params
andHttpMethod:@POSTandDelegate:self];

我收到的回复是

 
{error:{type:OAuthException,message:(#1)发生未知错误}}

这是Facebook图表API中的错误?我也尝试使用标准HTTPS请求进行此呼叫,并得到相同的结果。

解决方案

成功登录Facebook,您可以通过请求@/ me / accounts获取列表FanPage,并循环访问所需的粉丝页面,并通过向 @/ FBFanPageID?fields = access_token请求其accessToken



此accessToken与您的facebook.accesstoken不同。



在获取fanPage accessToken后,将其设置为Facebook accessToken由



[_ facebook setAccessToken :_accessTokenForFanPage]; //这是necc步骤



现在您可以通过 @/ FBFanPageID上传到fanPage墙/照片



请求fanPage专辑 @/ FBFanPageID / albums / p>

通过 @/ AlbumsID / photos上传到特定的专辑



对于上传这些图像参数字典将被使用。



NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
IMAGE,@ source,
IMAGECAPTION,@message,

nil];


I'm trying to upload a photo to a Facebook page I own using the iOS SDK and graph API. I've been able to upload photos to my own wall. I've also been able to post a message to my fan page wall as an admin and create an album on my fan page, so I think I'm making the right calls, but not succeeding.

This is what I'm currently doing.

I'm logging in using

Facebook *fb = [[Facebook alloc] init];
self.facebook = fb;
[fb release];
NSArray *permissions =  [[NSArray arrayWithObjects:@"read_stream", @"offline_access", @"publish_stream", @"manage_pages", @"user_photos", @"friends_photos",nil] retain];
[facebook authorize:FB_APP_ID permissions:permissions delegate:self];
[permissions release];

After I log in, I request the accounts

[facebook requestWithGraphPath:@"/me/accounts" andDelegate:self];

The accounts are returned to me with access tokens for each page and app I own. I use a simple loop to parse through the accounts to extra the access_token supplied for the page I wish to upload a photo to.

I then set my access token of my facebook object to the new access_token.

facebook.accessToken = new_accessToken;

and try and upload a photo my fan page using

UIImage *uploadImage = [UIImage imageNamed:@"t200.jpg"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
               uploadImage, @"source",
             @"test caption", @"message",
             nil];


[facebook requestWithGraphPath:@"/me/photos" andParams:params
        andHttpMethod:@"POST" andDelegate:self];

The response I receive is

{"error":{"type":"OAuthException","message":"(#1) An unknown error occurred"}}

Is this a bug in the facebook graph API? I also tried making this call using standard HTTPS requests, and get the same result.

解决方案

Ater successfully login to Facebook, you can get list FanPage by requesting @"/me/accounts" and iterate to the fan page you want and request its accessToken by making request to @"/FBFanPageID?fields=access_token"

This accessToken is different from your facebook.accesstoken .

After getting fanPage accessToken, set it as facebook accessToken by

[_facebook setAccessToken:_accessTokenForFanPage]; // this is necc step

Now you can upload to fanPage wall by @"/FBFanPageID/photos"

Request fanPage albums by @"/FBFanPageID/albums"

Upload to particular album by @"/AlbumsID/photos"

For uploading these image param dictionary will be used.

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: IMAGE,@"source", IMAGECAPTION,@"message",
nil];

这篇关于使用iOS SDK将照片发布到Facebook粉丝专页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 13:43