atymic/twitter

Helper functions do not seem to work with API v2 instance

ChrisHardie opened this issue · 2 comments

I tried linkTweet() and linkify() methods on an API v2 instance, and got undefined method errors.

Further, related to #339, it seems that the array structure used by the v2 API for individual tweets in the response is not affected by response_format and so if you try to use something like Twitter::forApiV1()->linkTweet($tweet) you get an error about missing object properties that are expected by the helper.

Would it be possible to update these helper methods to work with v2, or to clarify in the documentation that they are v1 only? Thank you.

I found this also. The functionality to linkify the tweet is in a trait so you can use that trait in any class you need. Bit "hacky" perhaps but should do in the interim.

use Atymic\Twitter\ApiV1\Traits\FormattingHelpers;

class MyComponent
{
    use FormattingHelpers;

    private $tweets;

    public __construct()
    {
        $response = json_decode(Twitter::userTweets("twitter_id", [
            "max_results" => 5,
            "tweet.fields" => 'created_at'
        ]));

        foreach($response->data as $tweet) {
            $parsed_text = $this->linkify($tweet->text);
            $tweet->text = $parsed_text;
            $this->tweets[] = $tweet;
        }

        $this->tweets = $response->data;
    }
}
atymic commented

Feel free to PR @titantwentyone as a v2 helper :)