Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

James Rush
PLUS
James Rush
Courses Plus Student 256 Points

Any idea how the Twitter follow button works on external sites?

Hello everyone, I am trying to figure out how Twitter and other sites make their iconic buttons similar to like and follow run on other sites securely through a javascript script. I have OAuth and I know that is part of the puzzle but I don't know how they've achieved this functionality of having an external site securely update their databases on an external action. I was wondering if anyone might know how it was done or how something similar might function, and if it is at all possible with PHP as I don't know much about Javascript, thank you for any help.

1 Answer

Kevin Korte
Kevin Korte
28,148 Points

You'll need Javascript to a degree, there isn't really any way around that. Yes, the buttons use Oauth 2 protocol. I know I couldn't build my own, without a lot more research, but it relies on the developer creating an "app" on the external services developer dashboard.

Then, when the user clicks one of these buttons, the request is sent to the external service (facebook, twitter, etc) asking the user to verify they authorize this "app" to access the api on their behalf, and shows the user what the developer of the "app" is requesting access to.

If the user accepts, a token is passed back. The "app" ( our service ) can then use that token to make requests to the API on the behalf the user.

Here's a good article that goes into more depth: https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2