Guest User

Untitled

a guest
Jan 10th, 2018
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. {"error":"unsupported_grant_type","error_description":"grant type not supported"}
  2.  
  3. public class SalesforceAuthentication
  4. {
  5. public SalesforceAuthentication()
  6. {
  7. }
  8. public static void authenticate()
  9. {
  10. string authUrl = 'https://login.salesforce.com/services/oauth2/token';
  11. HttpRequest req = new HttpRequest();
  12. req.setEndpoint(authUrl);
  13. req.setMethod('POST');
  14. req.setBody('grant_type=password&client_id=3MVG9ZL0ppGP5UrBcvLyXYRmRUuYKSgFgQayclpZBWmbi7PQ2vWj1V8Xev.GfE0C9xyWMrTzONlj2GZ0ow6VK&client_secret=2150505966475551576&username=manoj6893@gmail.com&password=manoj438sKQzXe5pXoMwIDn1IOIFZqQt');
  15. Http http = new Http();
  16. HttpResponse response = http.send(req);
  17.  
  18. AuthWrapper aw = (AuthWrapper)JSON.deserialize(response.getBody(),AuthWrapper.class);
  19. system.debug('auth response..!'+aw);
  20.  
  21. String serviceUrl = aw.instance_url+'/services/apexrest/Account/0012800000ro2xS';
  22. req = new HttpRequest();
  23. req.setEndpoint(authUrl);
  24. req.setMethod('GET');
  25. req.setHeader('Authorization','Bearer '+aw.access_token);
  26. req.setHeader('Content-Type','application/json');
  27. response = http.send(req);
  28. system.debug('server response..!'+response.getBody());
  29. }
  30.  
  31. public class AuthWrapper
  32. {
  33. public string access_token;
  34. public string instance_url;
  35. public string id;
  36. public string issued_at;
  37. public string signature;
  38. }
  39. }
Add Comment
Please, Sign In to add comment