/****************************************************************************************************************************** * Obtain authentication credentials, calling 'authenticate' only if necessary. * Most index.html authors can simply use this method to obtain auth credentials * after onDeviceReady. * success - The success callback function to use. * fail - The failure/error callback function to use. * PhoneGap returns a dictionary with: * accessToken * refreshToken * clientId * userId * orgId * loginUrl * instanceUrl * userAgent *****************************************************************************************************************************/ getAuthCredentials: function(success, fail) { PhoneGap.exec(success, fail, "com.salesforce.oauth","getAuthCredentials",[]); },
In the document, they said that we can get the user id using getAuthCreadentials. I am trying to get the user id using the below method.
You don't want to call Phonegap.exec in your success callback. What you probably want there is something along the lines of:
function success(response){
console.log(response.userId);
}
All Answers
It's returned in the oauth login response URI
access_token=[ACCESS TOKEN (Session Id)]
&refresh_token=[REFRESH TOKEN]
&instance_url=https%3A%2F%2Fna1.salesforce.com
&id=https%3A%2F%2Flogin.salesforce.com%2Fid%[ORG ID]%[USER ID]
&issued_at=1312403866216
&signature=[SIGNATURE]
Hi,
Thanks for your response.
var SalesforceOAuthPlugin = {
/******************************************************************************************************************************
* Obtain authentication credentials, calling 'authenticate' only if necessary.
* Most index.html authors can simply use this method to obtain auth credentials
* after onDeviceReady.
* success - The success callback function to use.
* fail - The failure/error callback function to use.
* PhoneGap returns a dictionary with:
* accessToken
* refreshToken
* clientId
* userId
* orgId
* loginUrl
* instanceUrl
* userAgent
*****************************************************************************************************************************/
getAuthCredentials: function(success, fail) {
PhoneGap.exec(success, fail, "com.salesforce.oauth","getAuthCredentials",[]);
},
In the document, they said that we can get the user id using getAuthCreadentials. I am trying to get the user id using the below method.
SalesforceOAuthPlugin.getAuthCredentials(success, getAuthCredentialsError);
function success(){
PhoneGap.exec(getAuthCredentials(userId()));
}
When I run the app, it says
getAuthCredentials called
getAuthCredentials successful
Error in success callback: com.salesforce.aouth3 = ReferenceError: userId is not defined at file:///android_asset/www/phonegap-1.2.0.js:773
You don't want to call Phonegap.exec in your success callback. What you probably want there is something along the lines of:
function success(response){
console.log(response.userId);
}
Thanks for your response Tom. Its working now.