# JS SDK, getTokenSilently, and Twitter API

**URL:** <https://community.auth0.com/t/js-sdk-gettokensilently-and-twitter-api/86711>\
**Category:** Get Help\
**Created:** [July 10, 2022, 7:36pm UTC](https://community.auth0.com/t/js-sdk-gettokensilently-and-twitter-api/86711 "2022-07-10T19:36:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![raymondcamden](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/raymondcamden/32/38661_2.png) [@raymondcamden](https://community.auth0.com/u/raymondcamden)\
**Post date:** [July 10, 2022, 7:36pm UTC](https://community.auth0.com/t/js-sdk-gettokensilently-and-twitter-api/86711/1 "2022-07-10T19:36:36Z")

</div>

Given a front end application that makes use of Twitter login, and using this as a guide:

> **[Learn About Auth0's new Single Page Apps (SPA) JavaScript SDK](https://auth0.com/blog/introducing-auth0-single-page-apps-spa-js-sdk/)**
>
> Auth0 has a new JS SDK for securing single page applications (SPAs) with best practices. Learn more about this JavaScript SDK here.

I discovered `getTokenSilently`, and tried to make calls to Twitter’s APIs with it. Right now I’m getting CORS errors, which is to be expected, but I was curious. I copied the result from getTokenSilently and tried to make the call locally, and I get 401 unauthored errors. Any ideas why?

Btw, I have _also_ tried using the Management API, and I get the same issue there: [Twitter Api returning Invalid or expired token - #2 by marektea](https://community.auth0.com/t/twitter-api-returning-invalid-or-expired-token/45021/2)

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [July 25, 2022, 10:03pm UTC](https://community.auth0.com/t/js-sdk-gettokensilently-and-twitter-api/86711/3 "2022-07-25T22:03:29Z")

</div>

Hi @raymondcamden,

The token returned from `getTokenSilently` is an access token _issued by Auth0_, not an access token issued by Twitter.

This token is not intended for use with API endpoints owned by Twitter. Instead, you are looking for IDP access tokens. Take a look at this doc for more info:

> **[Identity Provider Access Tokens](https://auth0.com/docs/secure/tokens/access-tokens/identity-provider-access-tokens)**
>
> Understand third-party access tokens issued by identity providers after user authentication and how to use them to call the third-party APIs.

---

<div class="post-metadata">

**Author:** ![raymondcamden](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/raymondcamden/32/38661_2.png) [@raymondcamden](https://community.auth0.com/u/raymondcamden)\
**Post date:** [July 26, 2022, 3:06pm UTC](https://community.auth0.com/t/js-sdk-gettokensilently-and-twitter-api/86711/4 "2022-07-26T15:06:53Z")

</div>

Ok, I did try this route, but had the same issues described here, [Twitter Api returning Invalid or expired token](https://community.auth0.com/t/twitter-api-returning-invalid-or-expired-token/45021). The token I got back from calling the Management API didn’t seem to ever work with Twitter.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [July 26, 2022, 3:46pm UTC](https://community.auth0.com/t/js-sdk-gettokensilently-and-twitter-api/86711/5 "2022-07-26T15:46:10Z")

</div>

Are you getting the same error from the twitter that is returned from the management API?

---

<div class="post-metadata">

**Author:** ![raymondcamden](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/raymondcamden/32/38661_2.png) [@raymondcamden](https://community.auth0.com/u/raymondcamden)\
**Post date:** [July 26, 2022, 4:01pm UTC](https://community.auth0.com/t/js-sdk-gettokensilently-and-twitter-api/86711/6 "2022-07-26T16:01:41Z")

</div>

The Auth0 management API works fine - but when I use the token against Twitter, I get what the user got in the other thread - the token is expired.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [October 27, 2022, 11:43pm UTC](https://community.auth0.com/t/js-sdk-gettokensilently-and-twitter-api/86711/7 "2022-10-27T23:43:44Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
