使用Facebook iOS SDK发布运行操作

时间:2013-12-20 11:40:42

标签: ios objective-c facebook facebook-sdk-3.0

我正在尝试使用Facebook iOS SDK中的Graph API。

到目前为止,我设法使用以下方式发布简单状态更新:

[connection addRequest:[FBRequest requestForPostStatusUpdate:@"Test"
     completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
         if (error) [self.appDelegate showUnknownCommunicationError];
     }];
[connection start];

接下来,我尝试使用provided sample:

发布运行操作
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[@"course"] = @"http://samples.ogp.me/136756249803614";

[FBRequestConnection startForPostWithGraphPath:@"me/fitness.runs"
                                   graphObject:action
                             completionHandler:^(FBRequestConnection *connection,
                                                 id result,
                                                 NSError *error) {
                                 // handle the result
                             }];

这不会引起任何错误,但我的墙上也没有任何错误。我认为这是因为,这个示例中的应用程序ID与我的不匹配,所以我试图像这样自己构建课程:

NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];

action[@"fb:app_id"] = FB_APP_ID;
action[@"og:type"] = @"fitness.course";
action[@"og:title"] = @"Sample Course";
action[@"og:image"] = @"https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png";
action[@"og:description"] = @"Test description";
action[@"og:url"] = @"https://mysite.pl/";

这会抛出错误并说,我的对象缺少课程属性。我现在很困惑......

针对我的应用运行的操作尚未恢复,但我想这不是重点,因为我正在使用我的开发者帐户进行测试。

修改。我从Facebook记录器获得了大量日志:

FBSDKLog: Request <#1111>:
  URL:  https://graph.facebook.com
  Method:   POST
  UserAgent:    FBiOSSDK.3.10.0
  MIME: multipart/form-data; boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f
  Body (w/o attachments):   
    batch_app_id:   1409052495999988
    batch:  [{"method":"POST","relative_url":"me\/fitness.runs?sdk=ios&migration_bundle=fbsdk%3A20131015&format=json&access_token=ACCESS_TOKEN_REMOVED","body":"course=http%3A%2F%2Fsamples.ogp.me%2F136756249803614"},{"method":"GET","relative_url":"method\/auth.extendSSOAccessToken?sdk=ios&migration_bundle=fbsdk%3A20131015&format=json&access_token=ACCESS_TOKEN_REMOVED"}]

2013-12-23 09:28:53.756 RunGuru[1559:60b] FBSDKLog: Response <#1111>
Duration: 1551 msec
Size: 1672 kB
Response Body:
(
        {
        body =         {
            id = 10201708817820717;
        };
        code = 200;
        headers =         (
                        {
                name = "Access-Control-Allow-Origin";
                value = "*";
            },
                        {
                name = "Cache-Control";
                value = "private, no-cache, no-store, must-revalidate";
            },
                        {
                name = Connection;
                value = close;
            },
                        {
                name = "Content-Type";
                value = "text/javascript; charset=UTF-8";
            },
                        {
                name = Expires;
                value = "Sat, 01 Jan 2000 00:00:00 GMT";
            },
                        {
                name = Pragma;
                value = "no-cache";
            },
                        {
                name = "x-fb-loadmon";
                value = "0,67.29,30";
            }
        );
    },
        {
        body =         {
            "error_code" = 3;
            "error_msg" = "Unknown method";
            "request_args" =             (
                                {
                    key = sdk;
                    value = ios;
                },
                                {
                    key = "migration_bundle";
                    value = "fbsdk:20131015";
                },
                                {
                    key = format;
                    value = json;
                },
                                {
                    key = "access_token";
                    value = ACCESS_TOKEN_REMOVED;
                },
                                {
                    key = "_fb_url";
                    value = "method/auth.extendSSOAccessToken";
                },
                                {
                    key = "_fb_profilable_request_id";
                    value = 1747586569;
                },
                                {
                    key = method;
                    value = "auth_extendssoaccesstoken";
                },
                                {
                    key = "_fb_batch_child_request";
                    value = 1;
                },
                                {
                    key = "_fb_batch_expires";
                    value = 1387787339;
                },
                                {
                    key = "_fb_batch_sig";
                    value = AfiDnh1EPSHTbQKV;
                }
            );
        };
        code = 200;
        headers =         (
                        {
                name = "Access-Control-Allow-Origin";
                value = "*";
            },
                        {
                name = "Cache-Control";
                value = "private, no-cache, no-store, must-revalidate";
            },
                        {
                name = Connection;
                value = close;
            },
                        {
                name = "Content-Type";
                value = "application/json";
            },
                        {
                name = Expires;
                value = "Sat, 01 Jan 2000 00:00:00 GMT";
            },
                        {
                name = Pragma;
                value = "no-cache";
            },
                        {
                name = "x-fb-loadmon";
                value = "0,67.29,30";
            }
        );
    }
)

2013-12-23 09:29:48.899 RunGuru[1559:60b] FBSDKLog: Request <#1115>:
  URL:  https://graph.facebook.com/1409052495999988?fields=supports_attribution,supports_implicit_sdk_logging,suppress_native_ios_gdp,name&format=json&migration_bundle=fbsdk%3A20131015&sdk=ios
  Method:   GET
  UserAgent:    FBiOSSDK.3.10.0
  MIME: multipart/form-data; boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f

2013-12-23 09:29:49.183 RunGuru[1559:60b] FBSDKLog: Response <#1115>
Duration: 283 msec
Size: 138 kB
Response Body:
(
        {
        body =         {
            id = 1409052495999988;
            name = RunGuru;
            "supports_attribution" = 1;
            "supports_implicit_sdk_logging" = 1;
            "suppress_native_ios_gdp" = 1;
        };
        code = 200;
    }
)

2013-12-23 09:29:49.207 RunGuru[1559:60b] FBSDKLog: Request <#1119>:
  URL:  https://graph.facebook.com/1409052495999988/activities?advertiser_tracking_enabled=1&url_schemes=%5B%22fb1409052495999988%22%5D&bundle_version=0.2&bundle_short_version=0.2&event=CUSTOM_APP_EVENTS&migration_bundle=fbsdk%3A20131015&sdk=ios&application_tracking_enabled=1&access_token=ACCESS_TOKEN_REMOVED&bundle_id=pl.runguru.ios.app&advertiser_id=A3D3020D-C158-4485-A2E3-E886FC4FA54D&format=json
  Method:   POST
  UserAgent:    FBiOSSDK.3.10.0
  MIME: multipart/form-data; boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f
  Body Size:    0 kB
  Attachments:  
    advertiser_tracking_enabled:    1
    url_schemes:    ["fb1409052495999988"]
    bundle_version: 0.2
    bundle_short_version:   0.2
    event:  CUSTOM_APP_EVENTS
    migration_bundle:   fbsdk:20131015
    sdk:    ios
    application_tracking_enabled:   1
    access_token:   ACCESS_TOKEN_REMOVED
    bundle_id:  pl.runguru.ios.app
    advertiser_id:  A3D3020D-C158-4485-A2E3-E886FC4FA54D
    format: json
    custom_events_file: <Data - 0 kB>

2013-12-23 09:29:49.421 RunGuru[1559:60b] FBSDKLog: Response <#1119>
Duration: 213 msec
Size: 4 kB
Response Body:
(
        {
        body =         {
            "FACEBOOK_NON_JSON_RESULT" = true;
        };
        code = 200;
    }
)

1 个答案:

答案 0 :(得分:1)

您的示例代码工作正常,奇怪的是,由于某种原因,活动没有出现在时间轴Feed上。如果您首先查看自己的个人资料,请查看应用的活动日志 - &gt;封面图片附近的活动日志按钮,你看它被创建了。

确认此方法的最佳方法是使用以下代码控制所有Facebook事件:

[FBSettings setLoggingBehavior:[NSSet setWithObjects:FBLoggingBehaviorFBRequests, nil]];

下次运行代码时,您将看到已发送的实际HTTP请求以及来自facebook的响应,该响应应包含图形对象的新ID。