J7mbo / twitter-api-php

The simplest PHP Wrapper for Twitter API v1.1 calls
MIT License
1.82k stars 800 forks source link

How do I request a user token (OAuth)? #265

Closed xbd63 closed 6 years ago

xbd63 commented 6 years ago

Hi there, I'm trying to follow the authentication process here: https://developer.twitter.com/en/docs/basics/authentication/api-reference/request_token

Using the following code I receive a message from Twitter saying "Sorry, that page does not exist".

Here's my code:

require_once( plugin_dir_path( __FILE__ ) . '../lib/TwitterAPIExchange.php');
$settings = array(
    'oauth_access_token' => $twitter_oauth_access_token,
    'oauth_access_token_secret' => $twitter_oauth_access_token_secret,
    'consumer_key' => $twitter_consumer_key,
    'consumer_secret' => $twitter_consumer_secret
);

$callback_url = urlencode(site_url() . '/settings');

$url = 'https://api.twitter.com/1.1/oauth/request_token.json';
$postfields = array(
    'oauth_callback' => $callback_url
);

$twitter = new TwitterAPIExchange($settings);
$results = $twitter->buildOauth($url, 'POST')
             ->setPostfields($postfields)
             ->performRequest();
$response = json_decode($results, true);

What's interesting is that Twitter says you only need to supply a Consumer key and Consumer secret, no need for the app's access token and access token secret. But if I reate the $settings object without those two parameters, your wrapper produces an error telling me to make sure I've used the correct parameters.

3RLikeNoOther commented 6 years ago

Did you solve this problem?

J7mbo commented 6 years ago

As this is an old issue, I'm closing it as perhaps you may not need it solved any more? But if you still feel that it needs to be addressed, please feel free to reopen or open a new issue and we'll solve it together as I will know it's important! Thanks! :)