Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {"error":"unsupported_grant_type","error_description":"grant type not supported"}
- public class SalesforceAuthentication
- {
- public SalesforceAuthentication()
- {
- }
- public static void authenticate()
- {
- string authUrl = 'https://login.salesforce.com/services/oauth2/token';
- HttpRequest req = new HttpRequest();
- req.setEndpoint(authUrl);
- req.setMethod('POST');
- req.setBody('grant_type=password&client_id=3MVG9ZL0ppGP5UrBcvLyXYRmRUuYKSgFgQayclpZBWmbi7PQ2vWj1V8Xev.GfE0C9xyWMrTzONlj2GZ0ow6VK&client_secret=2150505966475551576&username=manoj6893@gmail.com&password=manoj438sKQzXe5pXoMwIDn1IOIFZqQt');
- Http http = new Http();
- HttpResponse response = http.send(req);
- AuthWrapper aw = (AuthWrapper)JSON.deserialize(response.getBody(),AuthWrapper.class);
- system.debug('auth response..!'+aw);
- String serviceUrl = aw.instance_url+'/services/apexrest/Account/0012800000ro2xS';
- req = new HttpRequest();
- req.setEndpoint(authUrl);
- req.setMethod('GET');
- req.setHeader('Authorization','Bearer '+aw.access_token);
- req.setHeader('Content-Type','application/json');
- response = http.send(req);
- system.debug('server response..!'+response.getBody());
- }
- public class AuthWrapper
- {
- public string access_token;
- public string instance_url;
- public string id;
- public string issued_at;
- public string signature;
- }
- }
Add Comment
Please, Sign In to add comment