Twitter-API-v2-sample-code icon indicating copy to clipboard operation
Twitter-API-v2-sample-code copied to clipboard

js sample needs more parameter if that obtains user.fields

Open ricemountainer opened this issue 4 years ago • 1 comments

Hi experts

I'm so helpful that samples. However I found the small issue , so I would like to write it.

js sample parameter is below:

    const params = {
        "ids": "1278747501642657792,1255542774432063488", // Edit Tweet IDs to look up
        "tweet.fields": "lang,author_id", // Edit optional query parameters here
        "user.fields": "created_at" // Edit optional query parameters here
    }

But when we specify user.fields parameter, we also must specify "expansions" parameter. It is written by https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id

Actually I couldn't get user.fields response,and I added following parameter then it worked.

    const params = {
        "ids": "1278747501642657792,1255542774432063488", // Edit Tweet IDs to look up
        "tweet.fields": "lang,author_id", // Edit optional query parameters here
        "user.fields": "created_at" // Edit optional query parameters here
        "expansions": "author_id" // ** add here **
    }

Please check above.

Thank you

ricemountainer avatar Apr 16 '21 02:04 ricemountainer

Well spotted - I will add this the next time we revise the JS samples.

andypiper avatar Apr 23 '21 09:04 andypiper