【问题标题】:going crazy - how to set up an fb-app so my iOS-App can post to it's wall?发疯 - 如何设置一个 fb 应用程序,以便我的 iOS 应用程序可以发布到它的墙上?
【发布时间】:2012-10-16 21:02:49
【问题描述】:

好的,我知道如何在 USER 的墙上发帖(时间线?),效果很好。

我想要的是当用户在他的 iPhone 上做某些事情时,它应该显示为 APP 墙上的帖子。帖子应以 USER 的名义发帖。

类似:

幸运的卢克说:大家好

Zaphod Beeblebrox 开始使用 Awesomeapp

PLUS:只有应用程序的用户才能发布到应用程序的墙上(我看到页面的«管理权限»部分的设置,我可以设置谁可以发布到墙上。我不希望每个人发帖)

如果我是对的,该帖子也会自动出现在用户的供稿中,不是吗?还是我必须在用户的墙上发第二个帖子?

当用户首次使用应用程序时,我请求以下权限:@"user_photos",@"user_videos", @"manage_pages",@"read_stream", @"publish_stream",@"user_checkins",@"friends_checkins" ,@"email",@"user_location"

(最近添加了 read_stream 和 manage_pages,因为我在某处读到了 - 并没有帮助 :)

这是我用来发帖的一段代码:

NSString *graphPath = [NSString stringWithFormat: @"/%@/feed?access_token=%@", FBAppID, [FBAccessToken stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
    NSLog(@"graph path %@", graphPath);
    NSDictionary *postParams =
    @{
        @"Test": @"message"
    };


    [FBRequestConnection
     startWithGraphPath:graphPath
     parameters:postParams
     HTTPMethod:@"POST"
     completionHandler:^(FBRequestConnection *connection,
                         id result,
                         NSError *error) {

         if (error) {
             NSLog(@"error: domain = %@, code = %d, %@",
                          error.domain, error.code, error.description);
         } else {
             NSLog(@"Posted action, id: %@",
                          [result objectForKey:@"id"]);
         }
         // Show the result in an alert
     }];

返回错误 100(缺少消息或附件 - OAuthException)

我现在用谷歌搜索了两天,找不到任何合适的指导方针......帮助! :)

[编辑] 我可能正在做一些事情......

似乎NSDictionary *postParams @{@"Test": @"message"}; 是问题所在。 当我使用正确的[[NSDictionary alloc] initWithObjectsAndKeys: ...]; 时,它似乎可以工作......我们会看到:)

[编辑] 好的 - 我应该休息一下,看来...

使用@{...} 初始化字典需要先键,然后是对象,而 [NSDictionary dictionaryWithObjectsAndKeys:...] 先设置对象,然后是键...

我现在觉得有点傻……

【问题讨论】:

    标签: ios facebook post facebook-wall


    【解决方案1】:

    这就是我在我的代码中这样做的方式:

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"My app's name", @"name",
                                   @"Some cool caption", @"caption",
                                   @"Super description", @"description",
                                   @"http://stackoverflow.com//", @"link",
                                   nil];
    
    
    [FBRequestConnection startWithGraphPath:@"me/feed"
                                 parameters:params
                                 HTTPMethod:@"POST"
                          completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    
           .....
     }];
    

    请注意GraphPath,它与您的有点不同。在我的Info.plist 中还有一个 facebookId 值:

    <key>FacebookAppID</key>
    <string>123456789876543</string>
    

    和 facebook url 方案:

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb123456789876543</string> (fb + your app id)
            </array>
        </dict>
    </array>
    

    我已将facebookSDK 添加到项目中(我想你已经这样做了)

    所以这些东西至少足以让我贴到我的墙上

    所以请看一下你的facebookAppID,也许里面有东西, 以防万一这是official facebook tutorial

    【讨论】:

    • 谢谢 - 错误似乎是由于我对 NSDictionaries 的 @{...} 使用。当我将它更改为旧代码时,它开始工作......我想,这是因为我没有分配 NSDictionary,但你似乎也使用了一个临时字典并且它工作......奇怪......
    • 我很高兴有帮助。我不想写像字典初始化这样明显的东西,但我很高兴我这样做了 =)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-19
    相关资源
    最近更新 更多