简体   繁体   English

使用Facebook iOS SDK发布运行操作

[英]Posting run action using Facebook iOS SDK

I'm trying to use Graph API from Facebook iOS SDK. 我正在尝试使用来自Facebook iOS SDK的Graph API。

So far I managed to post simple status update using: 到目前为止,我设法使用以下方法发布了简单的状态更新:

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

Next I tried to post run action using 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
                             }];

This doesn't throw any error, but also nothing appears on my wall. 这不会引发任何错误,但是墙上也没有任何东西。 I thought it's because, the app id from this sample doesn't match mine, so I tried to build course myself like this: 我以为是因为此示例中的应用程序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/";

This throws error and says, that my object lack the course property. 这将引发错误并说我的对象缺少Course属性。 I'm confused now... 我现在很困惑...

The action Run for my app is not revieved yet, but I guess it's not the point since I'm testing it with my developer account. 我的应用程序“运行”操作尚未修订,但我想这不是重点,因为我正在使用开发人员帐户对其进行测试。

EDIT. 编辑。 I got tons of logs from Facebook logger: 我从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;
    }
)

Your sample code working fine, Strange thing is that the activity doesn't appear on there timeline feed for some reason. 您的示例代码运行正常,奇怪的是,由于某种原因该活动未显示在时间轴源上。 If you take a look at your activity log for your app by first going on your profile --> activity log button near cover pic, you see it been created. 如果您先通过在封面图片附近进入个人资料->活动日志按钮来查看应用程序的活动日志,就会看到该应用程序已创建。

Best method to confirm this works is to console out all facebook events using the following code: 确认这项工作的最佳方法是使用以下代码来控制所有facebook事件:

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

Next time you run your code you will see the actually HTTP request that been sent and also the response back from facebook which should contain the new id of the graph object. 下次运行代码时,您将看到实际发送的HTTP请求以及从Facebook返回的响应,其中应包含图形对象的新ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM