我们正在尝试创建Facebook测试用户使用Facebook iOS SDK 3.14.1根据他们的网站:https://developers.facebook.com/docs/graph-api/reference/v2.0/app/accounts/test-users
下面是我们的代码:NSString *fbAccessToken = [NSString stringWithFormat:@"%@",FBSession.activeSession.accessTokenData];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"true", @"installed",
fbAccessToken, @"owner_access_token",
nil
];
NSString *path = [NSString stringWithFormat:@"/%@/accounts/test-users", kFacebookID];
/* make the API call */
[FBRequestConnection startWithGraphPath:path ///{app-id}/accounts/test-users"
parameters:nil
HTTPMethod:@"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
)
{
if (result && !error)
{
NSLog(@"Test-User created successfully: %@", result);
}
else
{
NSLog(@"Error creating test-user: %@", error);
NSLog(@"Result Error: %@", result);
}
}];
当我们运行它时,我们收到以下错误:
error = {
code = 15;
message = "(#15) This method must be called with an app access_token.";
type = OAuthException;
};
我们也尝试了没有参数owner_access_token,但发生了同样的错误。我们如何使用Facebook iOS SDK以编程方式创建Facebook测试用户?
解决方案:
不要使用活动会话访问令牌,你应该使用应用令牌。只需替换fbsession . activessession . accesstokendata与您的应用令牌。
App令牌可以在这里找到:https://developers.facebook.com/tools/accesstoken/
根据上面的WizKid评论,这只是为了测试的目的。