图片发布到Facebook最后在错误的地方 [英] Picture post to Facebook ends up in the wrong place

查看:96
本文介绍了图片发布到Facebook最后在错误的地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将图片发布到Facebook页面,ID = 226338660793052,但是它仍然在/ me /照片中。我做错了什么?

  NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
imageToSend,@source,
facebookMes​​sageTextView.text,@message,
nil];
[facebook requestWithGraphPath:@/ 226338660793052 / photosandParams:params andHttpMethod:@POSTandDelegate:self];

我没有错误信息。我什么都没有,除了照片最后在我自己的专辑,我/照片,而不是在226338660793052 /照片的相册。



但是当我刚刚发布消息到该页面,我在页面的时间线上获得了一个成功的帖子:

  NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
@http://www.bitsonthego.com,@link,
@我的个人资料,@name,
facebookMes​​sageTextView.text,@message
nil];
[facebook requestWithGraphPath:@/ 226338660793052 / feedandParams:params andHttpMethod:@POSTandDelegate:self];

我在这里缺少什么?我知道这是可能的,因为我可以使用浏览器将图片上传到所需的页面,作为随机的非管理员用户。我似乎不能从图形API中执行。



更新:



我已经解决了部分问题。你必须使用目的地页面的access_token。这是你如何得到它:

  NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@access_token,@字段,
nil];
FBRequest * request = [facebook requestWithGraphPath:@226338660793052andParams:params andDelegate:self];

获得结果后,将其添加到上面的交易中:

  NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
image,@source,
[result objectForKey:@access_token] ,@access_token,
facebookMes​​sageTextView.text,@message,
nil];

FBRequest * request = [facebook requestWithGraphPath:[[result objectForKey:@id] stringByAppendingString:@/ photos] andParams:params和HttpMethod:@POSTandDelegate:self];

但是,这不会工作,因为Facebook.m将用默认用户access_token替换这个新的access_token ,所以我在166号线附近改变了Facebook.m:

  if([self isSessionValid]){
[params setValue:self.accessToken forKey:@access_token];
}

to:

  if([self isSessionValid]){
if([params valueForKey:@access_token] == nil)
[params setValue:self.accessToken forKey: @ 的access_token];
}

保留您指定的访问代码作为参数的一部分,从被弄脏通过Facebook.accessToken。现在这将把图片发布到我感兴趣的页面。



但是,这是因为我是有问题的页面上的管理员。其他用户将无法发布图片,并且图片将重新结束在自己的相册中,因为要访问该页面的access_token的调用将返回nil。



根据Facebook文档,如果该页面是无限制的,就像这个页面一样,那么应该可以发布图片:


注意:



对于需要访问令牌的连接,如果该页面是公开的,则可以使用任何有效的
访问令牌限制。
限制页面上的连接需要用户访问令牌,并且只有符合页面上设置的限制条件(例如年龄)的
用户可见。


我提到我的网页是公开的,没有限制?


页面访问令牌



要执行以下操作作为页面,而不是当前的
用户,则必须使用页面的访问令牌,而不是用于读取Graph API对象的用户访问令牌
。该访问令牌可以通过向
manage_pages权限发出HTTP GET / USER_ID /帐户来检索
。这将返回用户具有管理访问权限的页面列表(包括
应用程序配置文件页面),
以及这些页面的access_tokens。或者,您可以通过发出HTTP GET
到/ PAGE_ID?fields = access_token with themanage_pages权限,如上所述的
,为单个特定页面获取
页面访问令牌。除非另有说明,否则发布到页面还需要publish_stream
权限。


那么,如何将图片发布到公开/不受限制的页面?我可以从任何浏览器,所以这是可能的,但是如何使用Graph API?鉴于我可以发布到没有access_token shenanigans的饲料,怎么样发布图片是不同的?



总而言之,我要做的是发布图片,而不仅仅是缩略图URL,使用Graph API。

解决方案

我的问题在这一刻!我相信这个问题是你重写的框架线,这是不可能的,因为Facebook SDK现在是无法编辑的静态库。但是,我已经弄清楚如何创建不需要更改SDK的照片帖子 - 我使用从应用获取的令牌字符串创建新的令牌数据:

  FBAccessTokenData * tokenData = [FBAccessTokenData createTokenFromString:tokenString权限:[FBSession activeSession] .accessTokenData.permissions expirationDate:[FBSession activeSession] .accessTokenData.expirationDate loginType:FBSessionLoginTypeFacebookApplication refreshDate:零]; 

然后我用fb appID创建新的FBSession(和nullCacheInstance,不知何故似乎很重要):

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

然后我打开使用tokenData创建的新创建的会话,将此新会话设置为活动会话,它可以工作!

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

[FBSession setActiveSession:sessionFb];

然后通过Post参数和源图像调用PageAppID /照片的请求,并在Facebook上发布图像页面墙是从本身!

  [FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@%@ / photos,PageAppID]参数:params HTTPMethod:@POST completionHandler:^(FBRequestConnection * connection,id result,NSError * error){
}];

我认为activeSession的变化是类似于改变Facebook的线条。 p>

希望这有助于今天的某人


I am trying to post a picture to Facebook page with id= 226338660793052, but it keeps ending up in /me/photos. What am I doing wrong?

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   imageToSend, @"source",
                                   facebookMessageTextView.text, @"message",
                                   nil];
[facebook requestWithGraphPath:@"/226338660793052/photos" andParams:params andHttpMethod:@"POST" andDelegate:self]; 

I get no error message. I get nothing, except that the photo ends up in my own album, me/photos, and not in the album of 226338660793052/photos.

But when I just post a message to that page, I do get a successful post on the timeline of the page:

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"http://www.bitsonthego.com", @"link",
                                   @"my profile", @"name",
                                   facebookMessageTextView.text, @"message",
                                   nil];
[facebook requestWithGraphPath:@"/226338660793052/feed" andParams:params andHttpMethod:@"POST" andDelegate:self]; 

What am I missing here? I know this must be possible, as I can use a browser to upload a picture to the desired page, as a random non-admin user. I just can't seem to do it from the graph API.

UPDATE:

I've resolved part of the issue. You have to use the destination page's access_token. This is how you get it:

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"access_token",  @"fields",
                                   nil];
    FBRequest *request = [facebook requestWithGraphPath:@"226338660793052" andParams:params andDelegate:self];

When you get the result, then you add it to the transaction above:

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   image, @"source",
                                  [result objectForKey:@"access_token"], @"access_token",
                                   facebookMessageTextView.text, @"message",
                                   nil];

    FBRequest *request = [facebook requestWithGraphPath:[[result objectForKey:@"id"] stringByAppendingString:@"/photos"] andParams:params andHttpMethod:@"POST" andDelegate:self];

But, this won't work because Facebook.m will replace this new access_token with the default user access_token, so I made a change to Facebook.m at around line 166, from:

  if ([self isSessionValid]) {
        [params setValue:self.accessToken forKey:@"access_token"];
  }

to:

  if ([self isSessionValid]) {
    if ([params valueForKey:@"access_token"] == nil)
        [params setValue:self.accessToken forKey:@"access_token"];
  }

That keeps an access code you specify as part of the params, from getting clobbered by the Facebook.accessToken. Now this will post the picture to the page I am interested in.

However, this works because I am an admin on the page in question. Other users will not be able to post pictures and the pictures again will end up in their own albums, because the call to get an access_token for the page will return nil.

According to Facebook docs, if the page is unrestricted, as this page is, then it should be possible to post a picture to it:

NOTE:

For connections that require an access token, you can use any valid access token if the page is public and not restricted. Connections on restricted pages require a user access token and are only visible to users who meet the restriction criteria (e.g. age) set on the page.

Did I mention that my page is public and not restricted?

Page Access Tokens

To perform the following operations as a Page, and not the current user, you must use the Page's access token, not the user access token commonly used for reading Graph API objects. This access token can be retrieved by issuing an HTTP GET to /USER_ID/accounts with the manage_pages permission. This will return a list of Pages (including application profilePages) to which the user has administrative access, along with access_tokens for those Pages. Alternatively, you can get a page access token for a single, specific, page by issuing an HTTP GET to /PAGE_ID?fields=access_token with themanage_pages permission, as described above. Publishing to a Page also requires the publish_stream permission, unless otherwise noted.

So how does one post a picture to a public/unrestricted page? I can do it from any browser, so it is possible, but how is it done using the Graph API? Given that I can post to the feed with no access_token shenanigans, what about posting a picture is different?

In summary, what I am trying to do is to post a picture, not just a thumbnail URL, to a public/non-restricted page, using the Graph API.

解决方案

My issue as well at the moment! I believe the problem is with the lines in framework you rewrote, which became impossible since the Facebook SDK is now static library which can't be edited. However, I've figured out how to create the photos posts without having to change the SDK - I create new token data with the token string I get from an app:

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

then I create new FBSession with fb appID (and nullCacheInstance, somehow it seems to be important):

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

and then I open the newly created session with tokenData created up, set this new session to be the active session, and it works!

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

[FBSession setActiveSession:sessionFb];

Then calling request for PageAppID/photos with Post parameters and source image works, and it posts image on Facebook Page wall as being from itself!

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

I think the changing of activeSession is the thing that's similar to changing the lines in Facebook.m

hope this helps someone today

这篇关于图片发布到Facebook最后在错误的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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