I am brand new to salesforce development and am trying to connect to Salesforce to get the token.
I guess my question is 2 fold: 1) Do I have to use a webpage to authenticate with SF?
2) If not, why is this not working? When I try to use the username and password method of authenticating, I get: {"error":"unsupported_grant_type","error_description":"grant type 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 did try using grant_type = authorization_code but got another error:
{"error":"invalid_grant","error_description":"invalid authorization code"}