+ Start a Discussion
Varun99Varun99 

salesforce twitter integration failed

Hi all,

 

Am integrating twitter through salseforce but response failed and am getting below error

 

"failed to validate oauth signature and token"

 

 

Am passing accesstoken,secretkey and ect like this

 

Can any one help or suggest ?

 

string Stringval='OAuth oauth_callback="'+EncodingUtil.urlEncode('https://c.ap1.visual.force.com/apex/twitterForcepage', 'UTF-8')+'",oauth_consumer_key="eIGzjmMGeclmpSzxmjnKhQ", oauth_nonce="3de317379683f90d4f80da8879472036", oauth_signature="fiyY68Llzy2yREjUeJw0o%2Fdqcns%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1365504459", oauth_token="354671694-MrReLR18pmpDZulKaRVZR3CifKpI9ZFo1XUofyJn", oauth_version="1.0"';


string bVal=EncodingUtil.Base64Encode(blob.valueof(Stringval)); 
        String authorizationHeader = 'Bearer :' + bval;
        req.setHeader('Authorization',bVal);




 

 

Thanks in Advance.

kiranmutturukiranmutturu
may be u need to check the timestamp once.....You should be within about 5 minutes of twitter servers.. check the timestamp of the server once in Date HTTP header that twitter send in response to every request
Varun99Varun99

Hi Kiran,

 

 

Thanks for your reply, I changed my timestamp from twitter apps but still am facing same error.

 

Can you Please explain in brief how to change? 

 

 

Thank you

SurpriseSurprise

Hi Varun,

 

Please look at the code given below.It is not my code but from some other post in the forum.Somebody posted it and the other user used it and he said it is working.You can try and see if it helps you.

 

 

 

You can use the below sample code to update the status in to twitter directly form salesforce
------------ SAMPLE CODE ------------
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').rep

lace('@','%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 = '';
}