How to Create Custom Tokens for Twitter
How I created custom tokens of the Twitter API user information that is stored in the twitter_account table.
I am launching a site with a heavy Twitter focus using the Twitter module for user registration. The Twitter module does an avid job of authenticating but lacks a lot of function in integrating the data that is provided by the Twitter API that the module stores in the 'twitter_account' table. I would hope that the maintainers would mature the module to have a field mapping/merging feature similar to the Janrain/RPX module. This should include pulling in the user photo (I'll try to post how I cobbled together a solution for photos later) and tokenizing all user fields like the full name, description/bio, location, etc.
Views pulls in this information which works well for various page and block views but I wanted to inject the user details in the meta tags and page titles for SEO and search purposes. This is the recipe that I am using but please let me know if there's a better way.
Modules Used:
- Twitter 7.x-3.x-dev - Twitter heavy lifting. You need OAuth too.
- Custom Tokens 7.x-2.x-dev - Awesome module to avoid being beat up with token api
Very Basic Custom Token
Do you need to create the most basic of tokens? Do you need to be able to create a token that perhaps outputs just a single phrase or a even a single word? I needed to create a token for a piece of plain text information that would appear in multiple places all over my site, but was very likely to change from time to time. This is how I did it:
1. Go to Admin > Structure > Custom Token, click on Add Token
2. Enter a Token Name and Description
3. Choose "Custom Tokens" for the Token Type
4. In the PHP Replacement text area enter something like this:
$basictoken = 'My simple phrase or text';
return $basictoken;5. Hit "Save Token"
Back on the Custom Token main page you will now see your custom token outputted in the "demo" column. You can use this new token as an input filter if you have the Token Filter module installed.
The token will be [custom:basictoken]
Very Basic Custom Token with Domain Access
Here is a simple way to create a custom token that you can use with Domain Access. In this case there are only 2 domains, but you could easily adapt this as many domains as you want. To find out what domain uses which domain id go to Admin > Structure > Domains
1. Go to Admin > Structure > Custom Token, click on Add Token
2. Enter a Token Name and Description
3. Choose "Custom Tokens" for the Token Type
4. In the PHP Replacement text area enter something like this:
global $_domain;
if ($_domain['domain_id'] == 1 ) {
$basic_token = 'Some text for domain one';
return $basic_token;
}
else {
$other_basic_token = 'Some text for domain two';
return $other_basic_token;
}5. Hit "Save Token"
Back on the Custom Token main page you will now see your custom token outputted in the "demo" column. You can use this new token as an input filter if you have the Token Filter module installed.
The tokens will be [custom:basictoken] and [custom:otherbasictoken] respectively.
How to Retroactively Reward UserPoints to New Users
How to retroactively reward UserPoints to new users after they register for stuff they did when they were anonymous
This tutorial will show you how to reward anonymous users for interacting with your site, similar to khanacademy.org and queryblitz.com. An example is displaying a message like "You have collected 6 Awards! Log in or Register to claim your prizes."
This tutorial used Flags 2.0, Session API, UserPoints, Token, Custom Tokens, and Rules to give UserPoints to users after they have registered for flags they flagged before they registered.
To give UserPoints to anonymous users for flagging content, first set up a flag. We will call this flag "Awesome". Make sure both anonymous and authenticated users have access to this flag.
Next, create a new token with the Custom Tokens module, set the Type as User and in the PHP text area place the following, exactly as it shows here:
$uid = $account->uid;
$flag = flag_get_flag('awesome') or die('no "awesome" flag');
$count = $flag->get_user_count($uid);
print $count;