我是 Salesforce 开发的新手,正在尝试连接到 Salesforce 以获取令牌。
我想我的问题有两个:1)我必须使用网页来通过 SF 进行身份验证吗?
2)如果没有,为什么这不起作用?当我尝试使用用户名和密码方法进行身份验证时,我得到: {"error":"unsupported_grant_type","error_description":"grant type not supported"}
这是我的代码:
NSString *post = [NSString stringWithFormat:@"grant_type=basic-credentials&client_id=%@&client_secret=%@&redirect_uri=%@",
kOAuthClientID,
kOAuthClientSecret,
kOAuthClientAuthURL
];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:kOAuthClientTokenUrl]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error;
NSURLResponse *response;
NSLog(@"%@", request);
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@", data);
任何想法都会受到欢迎。
我确实尝试过使用 grant_type = authorization_code 但又遇到了另一个错误:
{"error":"invalid_grant","error_description":"无效授权码"}