How to get a user's oauth_access_token client-side like facebook, for server side integration

aproximation
@aproximation Wade McDaniel

In facebook I can get the user's authId relatively easily client-side. How would I do this via twitter on an AJAX site?

In the psudo-code below I get the Access Token if the user is logged in and pass that server side so I can do a server-side post. And if the user is not logged in/connected then facebook throws up a dialog that lets them log in, then returns (without refreshing the page) and executes a function that I can then get at the Access Token from.

Can this be done in twitter javascript, perhaps with @anywhere?

Thank you for your help!

  1.         if (FB) {
  2.             FB.getLoginStatus(function(response) {
  3.                 if (response.status === 'connected') {
  4.                     $.getJSON(window.page.services + "StoreAuthToken", { type: "facebook", socialId: response.authResponse.userID, authId: response.authResponse.accessToken, expiresInSeconds: response.authResponse.expiresIn }, null);
  5.                     window.dialogs.loadFacebookOverlay({ href: href, image: image, description: description, socialId: response.authResponse.userID });
  6.                 } else {
  7.                     FB.login(function(response) {
  8.                         if (response.status === 'connected') {
  9.                             $.getJSON(window.page.services + "StoreAuthToken", { type: "facebook", socialId: response.authResponse.userID, authId: response.authResponse.accessToken, expiresInSeconds: response.authResponse.expiresIn }, null);
  10.                             window.dialogs.loadFacebookOverlay({ href: href, image: image, description: description, socialId: response.authResponse.userID });
  11.                         } else { /* user cancled */ }
  12.                     }, { scope: 'share_item' });
  13.                 }
  14.             });
1 year 11 weeks ago

Replies

aproximation
@aproximation Wade McDaniel

For twitter I've got this so far.

  1.         if (twttr) {
  2.             twttr.anywhere(function(T) {
  3.                 if (T.isConnected()) {
  4.                     /* how do I get the auth token here? /
  5.                     window.dialogs.loadTwitter({ href: href, image: image, description: description });
  6.                 } else {
  7.                     / a pop-up is blocked - any way to allow it? */
  8.                     T.signIn();
  9.                 }
  10.             });
  11.         }

My questions are:
* How do I get the auth token if the user is already connected?
* The signIn tries to open a window but is blocked by the browser: is there a way to avoid this?

1 year 11 weeks ago
aproximation
@aproximation Wade McDaniel

I've made some progress. Now all I need is the auth token so I can do my server-side stuff.

I call the anywhere function like this

  1. $(window).bind("load", function(e) {
  2.     if (twttr) {
  3.         twttr.anywhere(function(T) {
  4.             window.twitter = T;
  5.         });
  6.     }
  7. });

Then I can call the signIn() without the pop-up being blocked. The problem is that the when I call window.twitter.bind("authComplete", function(e, user) { /* user data doesn't have the auth token */ });
So I can't send the auth token back to my server along with the user.data("id").

Now, how can I get the auth token now that I'm connected?

1 year 11 weeks ago
episod
@episod Taylor Singletary

@Anywhere is deprecated. It will be retired on March 5th, 2013. I wouldn't recommend using it.

API v1.1 and OAuth 1.0A aren't meant to be used through client-side Javascript. For the most part, what you're trying to do isn't possible using the API today.

1 year 11 weeks ago
aproximation
@aproximation Wade McDaniel

Lol, that figures that it's deprecated.
(I love your profile pic BTW!)

We're trying to mimic how the New York Times iPad app does twitter sharing - through a custom dialog that lives in an overlay, not a pop-up window. Are you saying that there currently isn't a way to do this?

If there is a way to do this is there some documentation somewhere on what endpoints we can converse with to allow a user to approve our app, get authentication and post a tweet? I can't find anything anywhere.

Thank you for your help!

1 year 11 weeks ago