+ Start a Discussion
h0llyh0lly 

Unauthorized

I'm just starting out with using chatter.

 

Using .net, in the developer edition, I make an httpwebrequest passing the oauth token and a GET method to mysalesforceurl/services/data/v28.0/chatter/users/userId and I get unauthorized.

 

I'm obviously missing something but don't know what.

Sonam_SFDCSonam_SFDC

hey Holly,

 

Could you please confirm if are  passing the access token in the Authorization http header, not as a query parameter, e.g. Authorization: Bearer ${my Access Token}

 

 

h0llyh0lly

Hi

Definately using header. Here is code extract

 

var webRequest = (Http WebRequest)

WebRequest.Create(uri);
webRequest.Headers.Add("Authorization", authorization token);
webRequest.Method = "GET";


var webResponse = (HttpWebResponse)webRequest.GetResponse(); //fails with message Unauthorized

 

The url I am using is the one created in the domain management, ie domainname.my.salesforce.com/services/data/v28.0/chatter/users

 

I don't know if the following is correct but I created a package containing a Connected App which contains the consumer key (under oauth settings) which I am using in the header.

 

The file chatter-rest-api-developer-deck.pdf indicates the following:

 

http get getrequest = new httpget(url0

getrequest.addheader("Authorization","OAuth" + mytoken)

 

I have tried:

 

webRequest.Headers.Add("Authorization", authorization token);

webRequest.Headers.Add("OAuth", authorization token);

webRequest.Headers.Add("Authorization", "OAuth " + authorization token);

 

(code slightly altered so the post could be submitted)

 

 

 

 

 

 

 

 

 

 

cplusplus_pleasecplusplus_please

Hi Holly, You need to give us the full error report aside from just "Unauthorized", because I believe Unauthorized can be several things. If you can grab the full error string, that would be great.

 

It would also be supplementary if you post the snippet of your code until you send the GET request.

 

 

=============================
Developer for www.voicent.com
Voicent provides CRM, auto dialer, predictive dialer, reminder, and call center solution that is suitable for anyone in any level
Voicent strives to meet customer demands to integrate Voicent software with CRM of their choice.

 

h0llyh0lly

ok I'm following instructions on www.salesforce.com/us/developer/docs/api_rest/api_rest.pdf from page 6.

 

Whereas before I interpreted the instructions to just pass the clientid in a header using the GET method I now discover that I need to request authorization,  and returns an authorization code which is then passed with the client_id, grant_type, client_secret, and redirect_url.

 

So I am trying to request authorization (for an app on the developer edition).

trying each of the following urls

 

https://login.salesforce.com/services/oauth2/authorize

https://test.salesforce.com/services/oauth2/authorize (I thought it should be this as it is a developer edition)

 

 

It requires: response_type, client_id and redirect_url

 

where 

response_type = code

client_id is the consumer key (from the settings in my app)

redirect_url is the redirect url  (from the settings in my app)

 

so I am passing these as parameters

 

I instantiate a web request:

 var webRequest = (Http WebRequest)WebRequest.Create(uri);

 

where uri is the url with params

 

I've set the webRequest.Method = "POST" and tried "GET"

 

and finally the response

 

var webResponse = (HttpWebResponse)webRequest.GetResponse();

 

at which point I get Bad Request 400.

 

(It is a console app I am using)

 

 

h0llyh0lly

Investigating further, I get:

 

error "error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration" string

 

I am using the callback url that is in the App settings (just below the consumer secret)

 

Found someone else having the same problem but no solution

http://boards.developerforce.com/t5/APIs-and-Integration/Integration-SalesForce-with-Heroku/td-p/658317

 

Disappointing