import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.*;
public class ChatterIntegrate {
/**
* @param args
*/
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
String oauthToken = "00DA0000000ao2F!ASAAQN3kdIrLpcdqrtUBEpKBJg_TK72qTx7urEh.AflgORiF05b_JVEDR1wjBFi9Y229Sni0MhJ1xRm3SJ8KsaM7M.O3_0ic";
String url = "https://na10.salesforce.com/services/data/v24.0/chatter/feeds/user-profile/me/feed-items";
String text = "My first post to Chatter via Java";
Part[] parts = {
new StringPart("text", text),
};
final PostMethod postMethod = new PostMethod(url);
try {
postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));
postMethod.setRequestHeader("Authorization", "OAuth " + oauthToken);
postMethod.addRequestHeader("X-PrettyPrint", "1");
HttpClient httpClient = new HttpClient();
httpClient.getParams().setSoTimeout(60000);
System.out.println(postMethod.getResponseBodyAsString());
} finally {
postMethod.releaseConnection();
}
}
}
0.000000
0.000000
Like this:
Like Loading...
Related
Published by Thys Michels
Cloud Architect - Salesforce and everything related
View all posts by Thys Michels
Published