2013-03-04 51 views
2

我奋力完成这个工作访问Twitter,我需要连接到Twitter REST API 1.1获取用户信息,时间线等如何从Salesforce

我来到对面什么是:

  1. 我有一个Twitter的应用程序与访问令牌,分泌等

现在如何使用所有访问令牌等,以从Salesforce发送(GET或POST)请求到Twitter。如何设置标题或如何验证请求。 该教程将非常有助于全所有我能找到的是对PHP等教程我需要它“销售人员”

注:我不想使用外部的lib

回答

0

你应该能够直接从Apex使用HTTP REST library来完成此操作。这里是first Google result"salesforce apex twitter integration"与这个示例代码Navatar_DbSup

VF CODE: 
<apex:inputTextarea id="tweetInput" onkeyup="return maxLength();" onKeyPress="return maxLength();" value="{!newTweet}" rows="2" cols="73"/> 
<apex:commandButton id="tweetBtn" style="height:35px;" value="Tweet" action="{!postTweet}" /> 
Controller code: 
*** post tweets into twitter*/ 
public String newTweet{get;set;} 
public Void postTweet() 
{ 
Http h = new Http(); 
HttpRequest req = new HttpRequest(); 
Method = 'POST'; 
req.setMethod(Method); 
req.setEndpoint('https://api.twitter.com/1/statuses/update.xml'); 
newTweet = newTweet.replace('%','%25').replace('&','%26').replace('@','%40').replace(';','%3B').replace('?','%3F').replace('/','%2F').replace(':','%3A').replace('#','%23').replace('=','%3D').replace('+','%2B').replace('$','%24').replace(',','%2C').replace(' ','%20').replace('<','%3C').replace('>','%3E').replace('{','%7B').replace('}','%7D').replace('[','%5B').replace(']','%5D').replace('`','%60').replace('|','%7C').replace('\\','%5C').replace('^','%5E').replace('"','%22').replace('\'','%27').replace('!','%21').replace('*','%2A').replace('(','%28').replace(')','%29').replace('~','%7F'); 
req.setBody('status='+newTweet); 
req.setHeader('Content-Type','application/x-www-form-urlencoded'); 

OAuth oa = new OAuth(); 
if(!oa.setService()) 
{ 
message=oa.message; 
} 
oa.sign(req); 
HttpResponse res = h.send(req); 
system.debug('&&&&&&&&&&&&&&&&7' + res.getBody()); 
PostTweetbody = res.getBody() + '___' + message; 
newTweet = ''; 
}