0

I am working on a iOS app with the last facebook SDK. I would like to publish an open graph object on the page's wall I administrate as the page itself. I've got the right permissions : "manage_pages", "publish_stream" and "publish_action".

Once I am logged in, I retrieve my accounts infos with the open graph request : /me/accounts I get the access_token to the page I want to publish to then I try to publish using this bit of code :

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) {
     }];
]};

I get the following 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"
)>}

Has someone managed to do something like this ? Any idea of what my error could be ?

thanks !

Cyril
  • 136
  • 1
  • 9
  • I don’t think Pages _can_ publish actions, that is something only user accounts can do. – CBroe Aug 12 '14 at 17:14
  • @CBroe : aww really? Where did you get this please? – Cyril Aug 13 '14 at 15:25
  • Wherever publishing an action is described in the docs, the code always starts with `/user-id/…`. And the general descriptions always mention a person as the actor publishing an action, there is no mentioning of pages publishing actions anywhere. In short: Actions are meant to primarily describe real-world activities people are undertaking; pages however don’t “do” stuff IRL, because they don’t have a “life”. – CBroe Aug 13 '14 at 15:32

0 Answers0