You need to sign in to do that
Don't have an account?
LOGIN_OAUTH_UNEXPECTED_ERROR
I have succesfully implemented REST API using oAuth in PHP application.
but i got error has occured during authentication.
Here with i showed my Coding
Initial request :
<?php
$token_url = LOGIN_URI . "/services/oauth2/token";
$curl = curl_init($token_url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
print_r($json_response);
?>
i get the Response :
Array
(
[id] => https://login.salesforce.com/id/00D90000000Y2YTEA0/00590000000hoxcAAA
[issued_at] => 1311080724805
[refresh_token] => 5Aep8617VFpoP.M.4tKc.wsyE74IvVIhBvqtmPoh2taT_UxhUv_nV7O2gR6LBFQ_bixsqEhRzQ30w==
[instance_url] => https://ap1.salesforce.com
[signature] => FmkAs7jSP5HfV5XsSQDn+ONH+g0aO1uuS0Eso+YHzk4=
[access_token] => 00D90000000Y2YT!AQ0AQAUzLVIubiAC7UnJtfo4V0r2gYQAwhr_5y6YkEJSX2R9Hc8JFgiPkYpCdh.RAz2BfdFKqg6sVfRhw6ct8g.f9zR32pab
)
using above access token, signataure i have formed the variable like
<?php
$post_fields = array(
'oauth_consumer_key' => '3MVG9Y6d_Btp4xp7PTQjzE8zY.4NJLD95rfMz3_fFk4_Oqb7ZMGMkx7CWHEVg3gRDhrtVUljTU3WZCnkvVWFo',
'oauth_token' => $access_token,
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_signature' => $signature,
'oauth_timestamp' => $issued_at,
'oauth_nonce' => $id,
'oauth_version' => '1.0'
);
$token_url = "$instance_url/services/OAuth/u/v20.0";
$curl = curl_init($token_url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,array("Authorization: OAuth $access_token"));
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$json_response = curl_exec($curl);
echo '<pre>';print_r($json_response);
?>
and i get the Error like
"LOGIN_OAUTH_UNEXPECTED_ERRORAn unexpected error has occured during authentication. Please try again."
anyone please help me to proceed further
thanks in advance
I am not a PHPer, but it looks like you are using oAuth 1.0 when it appears most fo your code is set up to use OAuth2 for the authenticated request:
see: 'oauth_version' => '1.0'
Thanks for your quick reply.
Now i changed instead of oAuth version 1.0 to 2.0 but still i got same error :(
'oauth_version' => '2.0'
What are you trying to actually do on the 2nd step? the rest api is at /services/data/.... but your url is /services/OAuth/u/v20.0
Hi
See this URL
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_guidelines_yourtools.htm?SearchType=Stem&Highlight=session|SESSION|Session|Sessions|sessions
passing the values like,
oauth_consumer_key
oauth_token
oauth_signature_method
oauth_signature
oauth_timestamp
oauth_nonce
oauth_version
above article says, if passing the above values in post method then,
Salesforce validates the request and sends a valid session ID to the consumer
like serverURL and sessionId etc.,
I am correct?
Thats for oauth 1, your first request to the oauth2 token service already returned you a valid access token, just use it.
Hi Simon,
Sorry i am not get u. can you please tell me little bit briefly?
thanks
Shakt