I am new to Salesforce and trying to connect to Salesforce to get a token.
I think my question is 2 times: 1) Should I use a web page to authenticate with SF?
2) If not, why doesn't it work? When I try to use the username and password authentication method, I get: {"error": "unsupported_grant_type", "error_description": "grant type is not supported"}
Here is my code:
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);
Any thoughts would be welcome.
I tried using grant_type = authorization_code, but got another error:
{"error": "invalid_grant", "error_description": "invalid authorization code"}
smcdrc
source share