如何使用Facebook ios sdk将自定义打开图形对象发布到页面?

时间:2014-08-12 14:36:14

标签: ios facebook facebook-graph-api facebook-ios-sdk facebook-page

我正在使用最后一个facebook SDK开发iOS应用程序。我想在我管理的页面墙上发布一个打开的图形对象作为页面本身。我拥有正确的权限:“manage_pages”,“publish_stream”和“publish_action”。

登录后,我使用打开的图形请求检索我的帐户信息:/ me / accounts 我得到access_token到我要发布的页面然后我尝试使用这段代码发布:

NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPostWithType:type title:title image:image url:url description:description];

graphPath  = [NSString stringWithFormat:@"/%@/feed/", pageid];

FBAccessTokenData *tokenData = [FBAccessTokenData createTokenFromString:token permissions:[FBSession activeSession].accessTokenData.permissions expirationDate:[FBSession activeSession].accessTokenData.expirationDate loginType:FBSessionLoginTypeFacebookApplication refreshDate:nil];
FBSession *sessionFb         = [[FBSession alloc] initWithAppID:@"573150882777167" permissions:[NSArray arrayWithObjects: @"publish_stream", @"publish_actions", @"manage_pages", nil] urlSchemeSuffix:nil tokenCacheStrategy:[FBSessionTokenCachingStrategy nullCacheInstance]];

[sessionFb openFromAccessTokenData:tokenData completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
  if (!error) { NSLog(@"Session changed correctly"); } else { NSLog(@"error creating new session %@", error); }
 }];

[FBSession setActiveSession:sessionFb];

// Creation of facebook object
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
  if(!error) {
    NSString *objectId                             = [result objectForKey:@"id"];
    NSLog(@"FB object id %@", objectId);
    NSMutableDictionary<FBOpenGraphAction> *action = (NSMutableDictionary<FBOpenGraphAction> *)[FBGraphObject graphObject];
    [action setObject:objectId forKey:@"ACTION_TYPE"];

    // we post to page wall as page; ##### DOESN'T WORK .... ###
    [FBRequestConnection startWithGraphPath:graphPath parameters:action HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
     }];
]};

我收到以下错误:

Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x177c7390 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ParsedJSONResponseKey={
    body =     {
        error =         {
            code = 100;
            message = "Unsupported post request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api";
            type = GraphMethodException;
        };
    };
    code = 400;
    headers =     (
                {
            name = Connection;
            value = close;
        },
                {
            name = "WWW-Authenticate";
            value = "OAuth \"Facebook Platform\" \"invalid_request\" \"Unsupported post request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api\"";
        },
                {
            name = "Facebook-API-Version";
            value = "v2.0";
        },
                {
            name = "Content-Type";
            value = "text/javascript; charset=UTF-8";
        },
                {
            name = Pragma;
            value = "no-cache";
        },
                {
            name = "Access-Control-Allow-Origin";
            value = "*";
        },
                {
            name = "Cache-Control";
            value = "no-store";
        },
                {
            name = Expires;
            value = "Sat, 01 Jan 2000 00:00:00 GMT";
        }
    );
}, com.facebook.sdk:ErrorSessionKey=<FBSession: 0x175c07f0, state: FBSessionStateOpen, loginHandler: 0x4b46e8, appID: 573150882777167, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategyNoOpInstance: 0x18951130>, expirationDate: 2016-08-06 14:25:07 +0000, refreshDate: 2014-08-12 14:10:52 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
    installed,
    "public_profile",
    email,
    "manage_pages",
    "publish_actions",
    "user_birthday",
    "user_location",
    "user_friends"
)>}

有人设法做了这样的事吗?知道我的错误是什么吗?

谢谢!

0 个答案:

没有答案