Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook iOS SDK errors – Posting Open Graph Actions

I'm attempting to post an open graph object with an action (using stories) to Facebook, but I always receive an error that doesn't give me any details. I summed up all the code I'm using into a single method for you guys:

- (void)publishToGraph {
    NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
    object.provisionedForPost = YES;
    object[@"title"] = @"Example title";
    object[@"type"] = @"rs-coupcash";
    object[@"description"] = @"Example description";
    object[@"url"] = @"http://exampleurl.com/idk";
    object[@"image"] = @[@{@"url": @"http://exampleurl.com/example_url.png", @"user_generated" : @"true" }];

    [FBSession openActiveSessionWithPublishPermissions:@[@"email", @"public_profile", @"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {

        if (!error && state == FBSessionStateOpen) {
            [FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

                if(!error) {
                    NSString *objectId = [result objectForKey:@"id"];
                    NSLog(@"Object ID: %@", objectId);
                    id<FBOpenGraphAction> actionObject = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
                    [actionObject setObject:objectId forKey:@"coupon"];
                    [FBRequestConnection startForPostWithGraphPath:@"/me/rs-coupcash:favorite" graphObject:actionObject completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

                        [[FBSession activeSession] close];
                        if(!error) {
                            NSLog(@"OG story posted, story ID: %@", [result objectForKey:@"id"]);
                        } else {
                            NSLog(@"Error: %@", error);
                        }
                    }];
                } else {
                    NSLog(@"Error: %@", error);
                }
            }];
        } else {
            NSLog(@"Error: %@", error);
        }
    }];
}

The error I get:

Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x114544670 {com.facebook.sdk:HTTPStatusCode=500, com.facebook.sdk:ErrorSessionKey=, expirationDate: 2014-08-26 05:18:45 +0000, refreshDate: 2014-06-27 16:56:32 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, **permissions**:( installed, "public_profile", email, "publish_actions" )>, com.facebook.sdk:ParsedJSONResponseKey={ body = { error = { code = 1; message = "An unknown error has occurred."; type = OAuthException; }; }; code = 500; }}

like image 906
afollestad Avatar asked Oct 31 '22 21:10

afollestad


1 Answers

I was using the wrong type for the open graph object; I was using just the namespace for the "type" value, it should be "rs-coupcash:coupon" in this case.

like image 112
afollestad Avatar answered Nov 15 '22 06:11

afollestad