MyBB Community Forums

Full Version: [TUTORIAL]Integrate Twitter Logins with MyBB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
This tutorial will show you how to integrate Twitter logins with MyBB. Users will be able to log in with Twitter. If the visitor has never visited before it will automatically make an account for that user. If the visitor has visited before it will log that user in.
Current users may also connect their accounts with Twitter.

Note that this tutorial does not cover how to post actions done on your forum to Twitter, as http://Screeze.com does.

See the similar tutorial for Windows Live here: http://community.mybboard.net/thread-65575.html

Requirements:
A server with PHP5 and SQLite
A set of Application and Secret keys from Twitter
Note: Callback URL for the Twitter app should be http://domain.com/forumdir/callback.php

Steps:

First, in the Admin CP, go to Templates & Style > Templates > Add Template

Give this new Template the following title:
Quote:twtregisteruname

Fill it in with the following HTML(edit where necessary)
 <html>
<head>
<title>Screeze: Select a username</title>
{$headerinclude}
<script type="text/javascript"> 
function process(f){
var now = new Date();
f.timezone.value = now.gettimezoneoffset();
return true;
}
</script>
</head>
<body>
{$header}
Hey {$twname}! It appears this is the first time you are logging into Screeze with your Twitter Account. Please select a username to use on Screeze and we'll log you in.<br/>
<form action="./callback.php" method="post" onsubmit="return process(this)">
Desired Username:<input name="username" type="text" value="{$twname}">
<input name="timezone" type="hidden" value="0">
<input value="Submit" type="submit">
</form>
<p>By clicking submit you acknowledge that you are over 13 and accept the Screeze Privacy Policy & Terms of Service.</p>
{$footer}
</body>
</html>
Save the template.

Repeat to create a new template. This template will be titled:
Quote:twdisconnect_normal

Fill it in with the following HTML(edit where necessary)
<html>
<head>
<title>Screeze:User Disconnection</title>
{$headerinclude}
<SCRIPT LANGUAGE="JavaScript">
  function redirect() {
    setTimeout("location.href='http://screeze.com/forum' ", 5000);
  }
  </SCRIPT>
</head>
<body onLoad="redirect()">
{$header}
<h2>Prompting Twitter account disconnection...{$fbdistat}</h2>
<br/>
Redirecting to forum index...
{$footer}
</body>
</html>
Save the template.

Now go to Configuration>Custom Profile Fields

Note the highest ID number currently listed.

Go to Add New Profile Field

Set the New Field to the following information:

Title: Twitter Token
Desc: Token
Type: Textbox
MaxLength: 65535
FieldLength: 0
Options: [Blank]
Display Order: One more than the ID you noted (Note this new number as well)
Required: No
Editable: No
Hide: Yes

Save this field and Add another

Set the New Field to the following information:

Title: Twitter Secret
Desc: Secret
Type: Textbox
MaxLength: 65535
FieldLength: 0
Options: [Blank]
Display Order: One more than the second ID you noted (Note this new number as well)
Required: No
Editable: No
Hide: Yes

Save this field and Add another

Set the New Field to the following information:

Title: Registered with Twitter
Desc: Registered
Type: Textbox
MaxLength: 65535
FieldLength: 0
Options: [Blank]
Display Order: One more than the third ID you noted (Note this new number as well)
Required: No
Editable: No
Hide: Yes

Save this field

Keep those three new IDs in a safe place for later.

Upload the callback.php file from the attached archive to your forum root. Edit the file where necessary.
NOTE: fid13, fid14 and fid15 should be changed with their respective fid numbers that you noted down, in order(Only replace the number part, leave fid there).

Upload the twitterOAuth directory from the attached archive to your forum root.


Upload the twlogin.php file from the attached archive to your forum root and edit where necessary.

Upload the twdisconnect.php file from the attached archive to your forum root and edit where necessary.

You may now direct your guests or logged in users to http://domain.com/forumdir/twlogin.php to connect their accounts with twitter(if the user has a normally registered account) or register and connect(to users without an account) or login(for users who have a connected account but are not logged in)

You may also direct your users to http://domain.com/forumdir/twdisconnect.php to dissassociate their Twitter account with your site.

Note that you may use the set profile fields to determine in code who is registered from Twitter.

Also note that users registered from Twitter will not have a proper email address set in their profile. You may ask these users after registration to provide one.

The TwitterOAuth library is the work of Abraham Williams ([email protected]) - http://abrah.am

The rest is my own(although registration and login is based off of the functions from MyBB's own scripting) and all I ask is that I am credited if anyone asks how the integration was accomplished and that the code is not sold to others(I think you may be breaking other licenses if you do as well but I am not sure). A mention on your site either on the Twitter connection pages, footer, or in any kind of announcement about the Twitter connectivity on your site with a link to http://screeze.com would be appreciated as well, but that's in no way required.

If anything isn't working right it may have been something I missed in this tutorial, so please let me know.
Alright this is awesome, thank you so much Wink. Now I did waste my time on making my own Toungue
:/ how configure the twitter key?
Just Google that there are tons of tutorials on that Wink.
hi,

hey, where can I get the twlogin.php

not in the attachment: S
(2010-02-27, 04:42 PM)DARKNESSDH Wrote: [ -> ]hi,

hey, where can I get the twlogin.php

not in the attachment: S

Oops Blush

It should be fixed now.
Very Good,

already installed and tested, this, 10.

check

http://www.gx-evolution.com/twlogin.php

okay?
nice Tut, I´ll try it later on my xampp installation... Thanks afrothunder
Thank you so much!
how add custom profile fields to the Twitter login ??
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14