"error":"invalid_grant","error_description":"Grant credentials are invalid"
public static string getAccessToken(){
String clientid = '*****';
String clientpassword = '*****';
string username = '*****';
string password = '*****';
String endpoint = 'https://api.box.com/oauth2/token';
String boxSubjectId = '19487182152';
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http h = new Http();
// Configure the request
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setHeader('Content-Type','application/x-www-form-urlencoded');
string payload = 'grant_type=client_credentials&client_id='+clientid+'&client_secret='+clientpassword+'&username='+username+'&password='+password;
system.debug('payload--'+payload);
req.setBody(payload);
res = h.send(req);
system.debug('res--'+res);
if ((res.getStatusCode() == 200 || res.getStatusCode() == 201) && res.getBody() != null && res.getBody() != null) {
Map<String, Object> untypedMap = (Map<String, Object>)JSON.deserializeUntyped(res.getBody());
if(untypedMap.containsKey('access_token')){
return (String) untypedMap.get('access_token');
}
return '';
}else{
return '';
}
Getting above error. Can anyone please let me know what mistake I am making here? Thanks
投稿コメントは受け付けていません。
コメント
0件のコメント