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
Draw Button on Top of Avplayer
Random Number from an Array Without Repeating the Same Number Twice in a Row
How to Integrate Fitbit API in iOS App Using Swift
Viewing Os_Log Messages in Device Console
Uitableviewcell Custom Class - Reload Cell Height After Change in Subview Height Constraint
Why Is the Title Being Repeated
I Want to Switch Time Scrubber to Do 15 Min Intervals
How to Draw a Simple Rounded Rect in Swift (Rounded Corners)
Swift/iOS Refreshing App Data When in Background
Swift 3 - Passing Data Between a View Controller and After That to Another 2
iOS Development App Startup Crash
Setting Default Tab in Uitabbar in Swift
How to Design an Uiscrollview in Storyboard
Change Buttonstyle Modifier Based on Light or Dark Mode in Swiftui
iOS Uiimagepickercontroller: Any Way of Getting the Date of the Chosen Picture
How to Create an Alert in a Swift File Model That Works for Various View Controller