Your Credentials Do Not Allow Access to This Resource Twitter API Error

Twitter API responds with Your credentials do not allow access to this resource while calling statuses/update.json

After comparing headers of outgoing requests from my server with the ones required by Twitter, I've noticed that Hybris doesn't add very important part of the header: oauth_token. At least it's not doing this in the code for Twitter adapter and for the scenario when you apply access token with setAccessToken(). It's just storing tokens in the inner storage but not initializing corresponding class member called consumerToken in OAuth1 class.
So to initialize the consumer token properly I've overridden the apiRequest method for Twitter class (before it used the defalut parent implementation) and added a small condition, so when consumer token is empty before the request - we need to try to init it.

public function apiRequest($url, $method = 'GET', $parameters = [], $headers = [])
{
if(empty($this->consumerToken)) {
$this->initialize();
}

return parent::apiRequest($url, $method, $parameters, $headers);
}

I'm not sure that I've fixed it the best way, but as long as it's working - that's fine.

How to Access Twitter App with another account?

You can use twurl to authenticate to another account. The account token and secret will be stored in the .twurlrc file in your home directory, you can use those to post from another account.

Posting to another user's twitter account from my app

Since you are instantiating the Twitter::REST::Client in an initializer using a fixed set of credentials, I'd assume that the client is always using the credentials with which it was instantiated.

In order to post a tweet on behalf of an Account, you'll want to instantiate a client that utilizes the credentials you are receiving from authorization, something like this:

class Account < ActiveRecord::Base
def twitter_client
Twitter::REST::Client.new do |config|
config.consumer_key = "2BN4jYtsf453374VM4m7HG"
config.consumer_secret = "LOE545ksfjkae3r8FOzj3NTHXVBfx8njPX0JHMNqCJs3mOnhQleH"
config.access_token = self.token
config.access_token_secret = self.secret
end
end
end

Then given an account, you could post like so:

account.twitter_client.update("Just setting up my twttr")


Related Topics



Leave a reply



Submit