Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper functions do not seem to work with API v2 instance #384

Open
ChrisHardie opened this issue Feb 9, 2022 · 2 comments
Open

Helper functions do not seem to work with API v2 instance #384

ChrisHardie opened this issue Feb 9, 2022 · 2 comments

Comments

@ChrisHardie
Copy link

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.

@titantwentyone
Copy link
Contributor

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
Copy link
Owner

atymic commented Apr 29, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants