ObjC,Facebook页面 - 发布新闻Feed的作品,但张贴照片不会 [英] ObjC, Facebook Page - posting news feed works, but posting photo does not

查看:118
本文介绍了ObjC,Facebook页面 - 发布新闻Feed的作品,但张贴照片不会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图在我的Facebook页面(我是管理员)从iPhone应用程序发布照片。我正在使用FB Sessions创建会话,获取读取权限,获取manage_pages权限,然后,我成功获取了我的Facebook Pages应用程序,作为

so I'm trying to post a photo on my Facebook page (I'm admin) from iPhone app. I'm using FB Sessions to create the session, get the read permission, get manage_pages permission, then, I successfully get my Facebook Pages app-ids as a result of

[FBRequestConnection startWithGraphPath:@"/me/accounts" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
 {
     NSLog(@"%@", [result description]);
 }]; // have token, what now?

哪个还好吧然后,我尝试向app_id /照片Feed发布照片,它不起作用=正确上传照片,但显示我(如我的个人资料)上传照片而不是页面本身。可能是什么问题?

Which is still fine. Then, I try to post a photo to the app_id/photos feed, and it does not work = it uploads the photo correctly, but shows me (as in my profile) uploading the photo rather then the Page itself. What could be the problem?

这是params和调用的代码

Here's the code for the params and the call

NSDictionary *params = [NSDictionary 
dictionaryWithObjects: [NSArray arrayWithObjects:
    [UIImage imageNamed:@"Icon.png"], 
    @"This is my first photo post from xcode app", nil] 
forKeys:[NSArray arrayWithObjects:
    @"source", 
    @"message", nil]];

[FBRequestConnection startWithGraphPath:@"MyPageID/photos" parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
 {
     NSLog(@"%@", [result description]);
 } ];

[result description] 调用是好的(它返回id = xx和post_id= yy,我认为是正确的),呼叫本身也是唯一的问题是它显示我作为作者,而不是页面本身。
MyPageID是正确的,因为调用

the [result description] log from the call is fine (it returns the id = xx and "post_id" = yy, which I assume are correct), as is the call itself - the only problem is that it shows me as the author, and not the Page itself. MyPageID is correct, because calling

NSDictionary *paramsFeed = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"This is my first page post from xcode app", nil] forKeys:[NSArray arrayWithObjects:@"message", nil]];

[FBRequestConnection startWithGraphPath:@"390106241058188/feed" parameters:paramsFeed HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
 {
     NSLog(@"result: %@", [result description]);
 }];

另外,调用我/照片并发布照片里有dictionaryKey @picture的作品,它的照片完全贴在我自己的墙上。

Also, calling me/photos and posting the photo there with dictionaryKey @"picture" works, and it posts the photo on my own wall perfectly.

有没有人知道这个问题可以隐藏在哪里? >

Do anyone knows where the problem could be hidden?

推荐答案

我找到了解决方案,虽然我觉得很奇怪,我不必这样做/ feed页面更新

I found the solution, although I find it weird that I did not have to do this for the /feed page update

非常感谢先生Arpit Kumar Kulshrestha 指出了我以前对此问题的正确方法( Xcode - 如何从iPhone应用程序分享照片到Facebook管理的页面Feed

Huge thanks goes for Mr. Arpit Kumar Kulshrestha, who pointed out the right way in my previous incarnation of the problem ( Xcode - how to share photo from iPhone app to Facebook managed page feed )

解决方案:
我以前尝试过设置一个新的 FBSession ,但它仍然有很多错误,所以我已经离开了这条路线到另一个然而,这样做是非常有道理的 -
创建 FBAccessTokenData ,其中有该页面的令牌,并将其他事情设置为与活动会话相同 - 像这样

the solution: I've tried setting a new FBSession before, but it still had a lot of errors in it, so I've left that route and went to another one. However, it makes perfect sense to do that - create FBAccessTokenData, which has the Page's token in it, and set other things to the same as the active session - like this

FBAccessTokenData *tokenData = [FBAccessTokenData createTokenFromString:pageTokenString permissions:[FBSession activeSession].accessTokenData.permissions expirationDate:[FBSession activeSession].accessTokenData.expirationDate loginType:FBSessionLoginTypeFacebookApplication refreshDate:nil];

然后,需要创建一个新的 FBSession ,什么是重要的,它需要将其tokenCacheStrategy设置为没有数据的东西,即 [FBSessionTokenCachingStrategy nullCacheInstance] 。我做了一个空白分配( [[FBSession alloc] init] ),这给了我很多错误,但是当我使用这个

then, one need to create a new FBSession, and what is important, it needs to have set its tokenCacheStrategy to something without data, i.e.[FBSessionTokenCachingStrategy nullCacheInstance] . I did a blank allocation ([[FBSession alloc] init]), and that gave me a lot of errors, however when I use this one

FBSession *sessionFb = [[FBSession alloc] initWithAppID:appID permissions:[NSArray arrayWithObjects: @"publish_stream", @"manage_pages", nil] urlSchemeSuffix:nil tokenCacheStrategy:[FBSessionTokenCachingStrategy nullCacheInstance]];

它工作得很好。当你有这个新的会话,你想打开数据来路径,你可以这样做:

it works perfectly. And when you have this new session, you want to open the path for the data to come and go, and you can make it like this:

[sessionFb openFromAccessTokenData:tokenData completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
 {

 }];

并且开始正常工作之前的最后一部分是将activeSession设置为此新分配和打开的会话,这样:

and the last part before it starts working correctly is setting the activeSession to this newly allocated and opened session, this way:

[FBSession setActiveSession:sessionFb];

在完成所有这些更改后,照片页面共享开始神奇地工作。
但是,我仍然不知道照片分享如何,但是Feed份额没有,但这解决了我的问题。

after I've made all of these changes, the photo page sharing started to work magically. However, I'm still not sure how is it possible that the photo share did not work before but the feed share did.. but this solves my issue.

这篇关于ObjC,Facebook页面 - 发布新闻Feed的作品,但张贴照片不会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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