You need to sign in to do that
Don't have an account?
Chatter Rest API and authorization confusion
I want to use the Chatter Rest API from a visualforce page since the ConnectAPi won't work for guest users
I created a connected app in a dev environment.
I am able to get an access token as long as I use the dev login that I used to create the connected app. I can't use a login from the sandbox instance that I am using. Is there a way to do so
Then I try running the following function
public ChatterUser getChatterUser(string userId){
String endpoint;
version = '/services/data/v36.0';
instanceUrl = System.Url.getSalesforceBaseUrl().toExternalForm();
endpoint= instanceUrl + version + '/chatter/users/' + userId;
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('GET');
req.setHeader('Content-type', 'application/json');
req.setHeader('Authorization', 'Bearer ' + accessToken);
HTTP http = new HTTP();
HTTPResponse resp = http.send(req);
System.Debug('Response:' + resp);
System.Debug('Response Body:' + resp.getBody());
}
and I get the following error
[Status=Unauthorized, StatusCode=401]
{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}
Can anyone see what I am doing wrong? It is kind of weird that I use a dev user and try to access data data from a sandbox instance. Does the authenticated user need Chatter access? Is there a way that I can use a production user to authenticate?