1

我将照片作为打开的图形对象上传,然后在它返回 URL 后将其绑定到我的打开图形操作中。

到目前为止一切正常,但我无法获得自定义用户消息“TEST TEST TEST TEST!” 露面。 我一直在从各个角度解决这个问题,但似乎无法确定它。有任何想法吗?

在此处输入图像描述

    - (void)postPhotoThenOpenGraphAction {

        FBRequestConnection *connection = [[FBRequestConnection alloc] init];

        // First request uploads the photo.
        FBRequest *request1 = [FBRequest requestForUploadPhoto:[UIImage imageWithData:[NSData dataWithContentsOfFile:picture.pathSmall]]];

        [connection addRequest:request1 completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

            if (!error) {
            } else {
                [self showFacebookFailedError];
            }
        }
                batchEntryName:@"photopost"];


        // Second request retrieves photo information for just-created
        // photo so we can grab its source.
        FBRequest *request2 = [FBRequest requestForGraphPath:@"{result=photopost:$.id}"];

        [connection addRequest:request2 completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

             if (!error && result) {

                 NSString *source = [result objectForKey:@"source"];
                 [self postOpenGraphActionWithPhotoURL:source];

             } else {
                 [self showFacebookFailedError];
             }
         }
         ];

        [connection start];


       }

    - (void)postOpenGraphActionWithPhotoURL:(NSString*)photoURL {

        id<PTOGPicture> photoGraphObject = [self pictureObjectForPicture:self.picture];
        id<PTOGSharePicture> action = (id<PTOGSharePicture>)[FBGraphObject graphObject];

        action.photo = photoGraphObject;

        if (self.selectedPlace) {
            action.place = self.selectedPlace;
        }
        if (self.selectedFriends.count > 0) {
            action.tags = self.selectedFriends;
        }

        action.message = @"TEST TEST TEST TEST!";

        if (photoURL) {

            NSMutableDictionary *image = [[NSMutableDictionary alloc] init];

            [image setObject:photoURL forKey:@"url"];

            NSMutableArray *images = [[NSMutableArray alloc] init];
            [images addObject:image];

            action.image = images;
        }

        // Create the request and post the action to the.
        [FBRequestConnection startForPostWithGraphPath:@"me/myappapp:share"
                                           graphObject:action
                                     completionHandler:^(FBRequestConnection *connection,
                                                         id result,
                                                         NSError *error) {
           //... code taken out for brevity

        }];
       }
4

1 回答 1

0

我有一个更简单的版本,可以满足您的需求:

首先,您根据需要创建您的操作对象:

- (void)shareOnFacebook {
    NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
    action[@"<OPEN_GRAPH_OBJ>"] = obj;
    action[@"image[0][url]"] = url;
    action[@"image[0][user_generated]"] = @"true";
    action[@"message"] = @"some message here";

    [FBRequestConnection startForPostWithGraphPath:@"me/<app_namespace>:<action>" graphObject:action completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    }];
}

但是,要使其正常工作,您必须在操作设置页面上设置这两个权限:

在此处输入图像描述

我希望它有所帮助。

于 2013-03-19T14:03:53.103 回答