通过新图表发布Facebook动作

时间:2015-05-04 18:24:42

标签: ios objective-c facebook facebook-graph-api

我只想尝试使用iOS SDK /新图表向Facebook发布操作。

  

问题是我一直收到警告说'行动至少要求   一个参考'它无效,因为它没有指定任何参考   对象。必须至少指定以下属性之一:   事件,朋友,最爱,提醒。

这是我目前的代码:

    FBSDKAccessToken *token = [FBSDKAccessToken currentAccessToken];
    FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
    NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
   NSMutableDictionary<FBGraphObject> *course = [FBGraphObject openGraphObjectForPost];
    course[@"og:title"] = @"My Event";
    course[@"og:type"] = @"myEventApp:event";
    course[@"og:url"] = [NSURL URLWithString:@"http://www.facebook.com"];
    course[@"og:description"]  = @"Yaba daba doo";
    action[@"course"] = course;

    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/myEventApp:add" parameters:action tokenString:token.tokenString version:@"v2.3" HTTPMethod:@"POST"];

    [connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                                if(error)
                                    NSLog(@"%@", error);
                                else
                                    NSLog(@"%@", result);

                            }];

    [connection start];

1 个答案:

答案 0 :(得分:1)

发布数据: 您应该添加权限@&#34; publish_actions&#34;

试试这段代码:

 if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
        // TODO: publish content.
        NSLog(@"published...");
    } else {
        FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
        [loginManager logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
            //TODO: process error or result.
        }];
    }