我想通过从我的应用程序发送 http 请求来创建 Facebook 打开图形对象,我不使用 Facebook SDK,我正在使用社交网络框架并构造请求以使用 AFNetworking 打开图形。我的代码:
- (void)didInitializeSocialAccountStore:(BOOL)succes forPermissions:(AccountStorePermissions)permissionsType
{
NSURLRequest *request = [self requestWithMethod:@"POST" path:[NSString stringWithFormat:@"https://graph.facebook.com/me/objects/myapp:comments?access_token=%@", [MGSocialNetworkSingleton sharedInstance].facebookAccesToken] parameters:self.exampleObject];
if (permissionsType == AccountStorePermissions_Publish)
{
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
DLog(@"response: %@\n", response);
DLog(@"JSON: %@\n", JSON);
DLog(@"URL: %@\n", request.URL);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
DLog(@"response: %@\n", response);
DLog(@"error: %@\n", error);
DLog(@"JSON: %@\n", JSON);
DLog(@"URL: %@\n", response.URL);
}];
[operation start];
}
}
- (NSDictionary *)exampleObject
{
return @{@"object":@{@"title":@"Titleeeee"}};
}
发出请求后,我收到此错误响应:
didInitializeSocialAccountStore:forPermissions:]_block_invoke_2 [第 432 行] JSON: { error = { code = 100; message = "(#100) 参数对象是必需的"; 类型 = OAuthException; }; }
我也在使用这种方法:
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
[self setParameterEncoding:AFJSONParameterEncoding];
[self setDefaultHeader:@"Accept" value:@"application/json"];
所以 exampleObject NSDictionary 应该自动转换为 JSON
编辑
此 curl 命令工作正常:
curl -X POST " https://graph.facebook.com/me/objects/myapp:comments " -F "access_token=CAAH3rJC7RHUBAHP6NHGaa5Pr2MKlJT4X9GZBZBkc93T9TNHqoSV411eD2uvOw2XInpZCZBryY4V6OtvHP5xMDZCJfyiieTe8IB1lS68gYkNlKj6bNYfcsPZCGpamC2wWVJDkAYm9hVHI3fASDGxbHKWUQYam8JZAwblA68y8HXZA1v2EaDZAe3VabyJQ37Q5rf6JVpWiRV50dKH9XSa7I7ZAcg9QajPhWnk3PEZD" -F "object={\"title\":\"Titleeeee\"}"