0

无论我尝试什么,我都无法让我的描述出现在 Facebook 上。我使用了调试器,生成的链接一切正常,并且 URL 填充了适当的数据。图片上传正常,但没有描述。我需要在应用程序的 Facebook 设置中设置什么吗?

以下是相关代码:

- (id<FBPost>)outfitObjectForOutfit{

id<FBPost> result = (id<FBPost>)[FBGraphObject graphObject];

NSString *format =
@"http://mysite.mobi/app/fbOpen.php?"
@"og:title=%@&og:description=%%22%@%%22&"
@"og:caption=%%22%@%%22&"
@"og:image=http://mysite.mobi/images/transBlank.png&"
@"body=%@";
result.url = [NSString stringWithFormat:format,
              @"New Post Title",fldDescription.text,fldDescription.text,fldDescription.text];
return result;
}

以及发布到FB的部分:

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

id<FBPost> outfitObject = [self outfitObjectForOutfit];

id<FBPostOutfit> action =
(id<FBPostOutfit>)[FBGraphObject graphObject];

action.outfit=outfitObject;

   if (photoURL) {
    NSMutableDictionary *image = [[NSMutableDictionary alloc] init];
    [image setObject:photoURL forKey:@"url"];

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

    action.image = images;
}
[FBSettings setLoggingBehavior:[NSSet
                                setWithObjects:FBLoggingBehaviorFBRequests,
                                FBLoggingBehaviorFBURLConnections,
                                nil]];
NSLog(@"%@",action);
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:fldDescription.text forKey:@"message"];
[FBRequestConnection startForPostWithGraphPath:@"me/appnamespace:action"
                                   graphObject:action
                             completionHandler:
 ^(FBRequestConnection *connection, id result, NSError *error) {
     NSString *alertText;
     if (!error) {
         alertText = [NSString stringWithFormat:
                      @"Posted Open Graph action, id: %@",
                      [result objectForKey:@"id"]];
     } else {
         alertText = [NSString stringWithFormat:
                      @"error: domain = %@, code = %d",
                      error.domain, error.code];
         NSLog(@"%@",error);
     }
     [[[UIAlertView alloc] initWithTitle:@"Result"
                                 message:alertText
                                delegate:nil
                       cancelButtonTitle:@"Thanks!"
                       otherButtonTitles:nil]
      show];
 }
 ];
 }
4

1 回答 1

1

我发现了我的问题。我混淆了 Facebook 示例所做的(活动发布)与发布到用户墙上的内容。这就是我必须做的所有事情才能让它工作:

NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:fldDescription.text forKey:@"message"];
[params setObject:UIImagePNGRepresentation(userImage) forKey:@"picture"];

[FBRequestConnection startWithGraphPath:@"me/photos"
                             parameters:params
                             HTTPMethod:@"POST"
                      completionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error)
 {
     if (error) {

         [[[UIAlertView alloc] initWithTitle:@"Result"
                                     message:@"Sorry there was an error posting to Facebook."
                                    delegate:nil
                           cancelButtonTitle:@"OK"
                           otherButtonTitles:nil]
          show];
     }
 }];

我还应该提到,我必须进入我的应用程序的 opengraph 设置并允许用户消息和用户生成的照片。

于 2013-04-05T19:01:51.917 回答