You need to sign in to do that
Don't have an account?
Yury.K
oAuth 2.0, Access token as parameter
Hello everyone,
I'm using REST API to be authorized in Force.com, I have no problem with getting and using access token. Im using access token as header, everything works perfectly.
But I wonder if I can use access token, as parameter in URL?
So url parameter will look like :
&access_token=<access token>
Is it possible? If yes - which variable in parameter should I use ?
Thanks and Regards,
Yury.
Hi,
You can send a request by setting access token in the header.
Try the below code snippet.
http h1 = new http();
httprequest req1 = new httprequest();
req1.setEndpoint('https://ap1.salesforce.com/services/data/v20.0/sobjects/Account/');
req1.setMethod('GET');
req1.setHeader('Accept', 'application/xml;charset=UTF-8'); // When you use setMethod as 'GET' To get response in xml format.
req1.setHeader('Authorization:', 'OAuth ' + acc_tken); // you can set access Token here in the header, after this send your request
// req1.setTimeout(60000);
httpresponse res1 = h1.send(req1);
string result1 = res1.getBody();
system.debug('@@@@@@@@@@@@@@@@@@_________________________result__________________________' +result1);
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
I know how to send it in header, got this logic and it's working perfectly.
But in my scenario I need to use it in URL address(if its possible).
Thanks and Regards,
Yury.
Hi,
The client application can use the access token to authorize requests against the resource server (the Force.com instance specified by the instance URL) via the REST APIs, providing the access token as an HTTP header in each request.
You can't use it in url.