function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
moh3enmoh3en 

force.com identity service (id url via oauth2) please need help!

Hi,

I am trying to get the following output in my code. I already have my instance url and access_token. In the documentation for Oauth2, it tells me to send a get request to the id url followed by an OAuth authorization HTTP header containing the access token. Can someone please give me a sample code on how can I send a get request to the id url? I am trying to get the url for the api endpoint. 

{
	"id":"https://login.salesforce.com/id/00D50000000IZ3ZEAW/00550000001fg5OAAQ",
	"asserted_user":true,
	"user_id":"00550000001fg5OAAQ",
	"organization_id":"00D50000000IZ3ZEAW",
	"username":"user@example.com",
	"nick_name":"user1.2950476911907334E12",
	"display_name":"Sample User",
	"email":"user@example.com",
	"status":{
		"created_date":"2010-11-08T20:55:33.000+0000",
		"body":"Working on OAuth 2.0 article"
	},
	"photos":{
		"picture":"https://c.na1.content.force.com/profilephoto/005/F",
		"thumbnail":"https://c.na1.content.force.com/profilephoto/005/T"
	},
	"urls":{
		"enterprise":"https://na1.salesforce.com/services/Soap/c/{version}/00D50000000IZ3Z",
		"metadata":"https://na1.salesforce.com/services/Soap/m/{version}/00D50000000IZ3Z",
		"partner":"https://na1.salesforce.com/services/Soap/u/{version}/00D50000000IZ3Z",
		"rest":"https://na1.salesforce.com/services/data/v{version}/",
		"sobjects":"https://na1.salesforce.com/services/data/v{version}/sobjects/",
		"search":"https://na1.salesforce.com/services/data/v{version}/search/",
		"query":"https://na1.salesforce.com/services/data/v{version}/query/",
		"recent":"https://na1.salesforce.com/services/data/v{version}/recent/",
		"profile":"https://na1.salesforce.com/00550000001fg5OAAQ"
	},
	"active":true,
	"user_type":"STANDARD",
	"language":"en_US",
	"locale":"en_US",
	"utcOffset":-28800000,
	"last_modified_date":"2011-01-14T23:28:01.000+0000"
}

 I used curl to do the request, but I can not seem to find out why it does not return anything. $url is my  id url and $access_token is my token.  The returning status is always 302 instead of 200. Please I need help on figuring why this is happening. I've red the oauth documentations so many times, but I still can not figure what is wrong. Please I would appreciate it if someone had a look at my code.

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
            array("Authorization: OAuth $access_token"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ( $status != 200 ) {
        die("Error: call to URL $url failed with status $status, response $json_response, curl_error " .     curl_error($curl) . ", curl_errno " . curl_errno($curl));
    }

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

302 is a redirect, you need to follow the redirect (there's probably a curl option for that)

All Answers

SuperfellSuperfell

302 is a redirect, you need to follow the redirect (there's probably a curl option for that)

This was selected as the best answer
ashish raiashish rai

Hello,

  Hey i am facinh the same problem so can you please post the code that how you retrive the data from cURL making request with cURL.

rajendra jadhavrajendra jadhav

I have also same problem. Can some body can post code here to get solution?.