Reputation: 11
I'm simply trying to post an action to Facebook using the iOS SDK / new graph.
Problem is I keep getting an alert saying 'Action Requires at Least One Reference' It's invalid because it does not specify any reference objects. At least one of the following properties must be specified: event, friend, favorite, reminder.
Here is my current code:
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];
Upvotes: 1
Views: 449
Reputation: 119
Posting Data: You should add permission @"publish_actions"
Try this code:
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.
}];
}
Upvotes: 1