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
kodeXkodeX 

cUrl statement to access Chatter API

As given in salesforce chatter REST api documentation,

I am trying to access Chatter using the following cUrl statement-

 

curl -X --insecure GET https://na1.salesforce.com/services/data/v23.0/chatter/users/me 
     -H 'Authorization: OAuth 00DD0000000FJ6T!AQkAQPde_DMF2vGzddfZmBRS95Goj DbtArKkgukAgZP0OVFYY5KkAqhLw9ejeKIlpJ3FgwGAWeRlBiWRt8mfXEuAZGbZNosk'

 

 

I have fitted my access token exactly after 'OAuth' in the above format.

 

After execution on  cmd prompt of above cUrl stmt,

cUrl is giving the following error-

 

curl: (6) Could not resolve host: GET; Host not found
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.
curl: (6) Could not resolve host: OAuth; Host not found
curl: (6) Could not resolve host: 00DD0000000FJ6T!AQkAQPde_DMF2vGzddfZmBRS95GojDbtArKkgukAgZP0OVFYY5KkAqhLw9ejeKIlpJ3FgwGAWeRlBiWRt8mfXEuAZGbZNosk'; No data record of requested type

 

Please carefully see that i have given the "--insecure" option to disable certificate verification.

 

Why is cUrl unable to resolve the salesforce website address?

How to solve this?

 

Seriously, my chatter project is at a standstill and so a quick fix for above problem is needed!

Sincerely,

kodeX

Best Answer chosen by Admin (Salesforce Developers) 
kodeXkodeX

Forget cUrl!!!

PROBLEM SOLVED THROUGH simple JAVA code!!!

Remember if you get invalid session_id, username,password,token error after executing the code below, then your access token has expired.

Use the refresh token to retrieve a new access token again. See the Using refresh token

Once u retrieve the access token, you can fit that in the string value below, and use it further.

 

Solution-

String accesstoken="access token value"
String staticurl="https://ap1.salesforce.com/services/data/v23.0";
String resourceurl="/chatter/feeds/news/me/feed-items";//will change with what you want to do

 

HttpMethod gm=new GetMethod(staticurl+resourceurl);//append

 

Header h1=new Header("Content-Type", "application/json");

 

HttpClient client=new HttpClient();

try{
            gm.setRequestHeader("Authorization", " OAuth "+accesstoken);

            gm.setRequestHeader(h1);
            client.executeMethod(gm);
            System.out.println(gm.getResponseBodyAsString());

            gm.releaseConnection();

 

    }catch(Exception e){System.out.println(e);}

 

Understand all below-

 

References-