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

Support API V2 and Ads API #927

Closed
willemverspyck opened this issue Jan 22, 2021 · 1 comment
Closed

Support API V2 and Ads API #927

willemverspyck opened this issue Jan 22, 2021 · 1 comment

Comments

@willemverspyck
Copy link

TwitterOAuth is very nice tool to connect to the Twitter API, but I really mis connecting the Ads API and now API V2. For Twitter Ads API is an issue for, but it's already 3 years old. I understand if you don't have time for it, but can I make an PR with these changes:

private function http(
        string $method,
        string $host,
        string $path,
        array $parameters,
        bool $json
    )

And change it to (with protected possible to override):

protected function http(
        string $method,
        string $url,
        array $parameters,
        bool $json
    )

Create new method:

protected function getUrl(string $host, string $path)
{
    return sprintf('%s/%s/%s.json', $host, self::API_VERSION, $path);
}

And change these methods (also put, post, upload, etc):

public function get(string $path, array $parameters = [])
{
    return $this->http('GET', self::API_HOST, $path, $parameters, false);
}

To:

public function get(string $path, array $parameters = [])
{
    $url = $this->getUrl(self::API_HOST, $path);

    return $this->http('GET', $url, $parameters, false);
}

As far as I can see, it will be BC (but I have to test that). With the method "http" being protected I can extends this class and only change the getUrl method to support API V2 or Twitter Ads API.

class TwitterV2 extends TwitterOAuth {
    const API_VERSION = '2';

    protected function getUrl(string $host, string $path)
    {
        return sprintf('%s/%s/%s.json', $host, self::API_VERSION, $path);
    }
}

Or:

class TwitterAds extends TwitterOAuth {
    const API_VERSION = '7';

    protected function getUrl(string $host, string $path)
    {
        return sprintf('%s/%s/%s', $host, self::API_VERSION, $path);
    }
}

Twitter Ads doesn't accept .json at the end of the URL.

Please let me know! I can an PR for this.

@abraham
Copy link
Owner

abraham commented Jul 18, 2021

v2 API support has been added in release 3.0.0. Supporting the Ads API is being tracked with #684.

@abraham abraham closed this as completed Jul 18, 2021
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

Successfully merging a pull request may close this issue.

2 participants