mironal / TwitterAPIKit

Swift library for the Twitter API v1 and v2 🍷
MIT License
119 stars 24 forks source link

Unable to retrieve email from Twitter account #132

Closed HyunjoonKo closed 2 years ago

HyunjoonKo commented 2 years ago

Hi. I was originally using TwitterKit, but I'm going to switch to this library. But I ran into a problem implementing it.

I want to get the account email through v1 getAccountVerify, but the function does not work. Can you help? My implementation code looks like this:

// after login

self.client = .init(
    consumerKey: consumerKey,
    consumerSecret: consumerSecret,
    oauthToken: oauthToken,
    oauthTokenSecret: oauthTokenSecret
)

self.client
    .v1
    .account
    .getAccountVerify(.init(skipStatus: true, includeEmail: true, includeEntities: false))
    .responseObject { response in
        print("responseAccount > \(response.success)")
    }

On TwitterKit I was able to get the email value by calling include_email true in the same /1.1/account/verify_credentials.json. But I can't get it from this library.

mironal commented 2 years ago

Thanks for using TwitterAPIKit!

I tried "GET account/verify_credentials" and was able to get the email.

email

Here is the code.

let client = TwitterAPIClient(
    consumerKey: "my-key",
    consumerSecret: "my-secret",
    oauthToken: "my-token",
    oauthTokenSecret: "my-token-secret"
)

let response = await client.v1.account
    .getAccountVerify(.init(skipStatus: true, includeEmail: true, includeEntities: false))
    .responseObject

    print(response.prettyString)

Here are the steps I took to get the email.

Turn on the "Request email from users" switch in your developer portal

image

Regenerate token

Perhaps this step may not be necessary. I forgot my token and had to regenerate it.

Run getAccountVerify(.init(skipStatus: true, includeEmail: true, includeEntities: false))

I was able to run the code and verify that the response contained the email.

Please double check

Since you are already using TwitterKit, your application is probably already configured in the Developer Portal, but please double check.

And could you double check that the account you are using has the email set up and verified? The API documentation says that if verification is not complete, null will be returned.

https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-account-verify_credentials If the user does not have an email address on their account, or if the email address is not verified, null will be returned.

HyunjoonKo commented 2 years ago

Hi @mironal

Thank you for answer.

There was a problem with the settings in the Twitter Developer Dashboard. It wasn't a library issue😅