Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Twitter Integration with Eclipse (Testing Version)


Exception
 Share

Recommended Posts

Hello guys! It's been a while since I've done a tutorial (Or anything, for that matter. I've been quite lethargic.), so I wanted to end my period of inactivity. A good start I thought would be with a tutorial. Twitter as a social platform is incredibly important, and if you want your game to have players, I believe it is a fundamental resource that you should just plain exploit to your advantage.

**Now, a quick warning: this is VB6, and not only that, I'm combining the use of PHP (Purely to massively cut my time spent debugging/making!). This is also an initial testing version, and while I have tested it for myself, I cannot say the same for others. Because it's VB6, this is -_sketchy_-, I cannot deny that. That does not mean to say that it's dysfunctional, insecure, or bad in any way…the way it works is just rather arbitrary. :'P**

@**PHP DEVS**: I'm obviously not the best with PHP (Or security, in general. :'P), so, please do point out any security or functionality flaws! I'd like to do my best to get this as functional and secure as possible!

@**USERS**: This is obviously new. It is currently usable, but that doesn't mean to say it is flawless. I would wait a short while before you go ahead with this, but I'm not going to stop you! I will offer support, though!

First off, you **require**:

- A **webserver with PHP installed**.

- A **Twitter** account. That's an important part. :'P

- **Any Eclipse Origins derivative**, whether it be Origins, Nightly, CSDE, Advanced, or your own edit. It'll work, there's no rendering involved.

- **You also require basic PHP knowledge and basic security ideology.** Don't blame me if people can find a link to tweet on your account if you make it blindingly obvious.

- **The same for VB6, just with common sense instead of security ideology.** This is fairly straightforward, take this one task at a time, rather than trying to do everything simultaneously!

Anyway, do you meet the requirements? Yes? Carry on then, you're good.

Now, log into Twitter. After you've logged in, head to **[https://dev.twitter.com/apps/new](https://dev.twitter.com/apps/new)** . This will allow you to create a new application, which will enable you to utilise the APIs involved. On the main page, scroll down a bit to create an access key, so you can use it shortly.

After you're done with that, you can download TwitterOAuth at **[https://github.com/a…hive/master.zip](https://github.com/abraham/twitteroauth/archive/master.zip)** .

When that's finished, stick it all on an obscure directory somewhere on your webserver, and **stick an index.php/html, and a .htaccess, for extra precaution**. Shady, I know, but I don't feel like attempting to integrate this crap into VB6\. _You_ go do that if you please, as this is a tutorial for YOUR development. I just practically more-than-halved the time taken to just use PHP.

Got it somewhere, and closed off? Good. Create a new PHP file, name it "tweet.php" (Or whatever you want, really.), and stick it in that directory. Open it up, and stick in

```

post('statuses/update', array('status' => $post));

?>

```
**Source: [http://www.damnsemic…ost-twitter-api](http://www.damnsemicolon.com/php/php-auto-post-twitter-api)**

Now, see those variables with "xxx" in place? We **need** to replace them. Head back to the application that you created on the Twitter development site, and open the OAuth tab. For OAuth settings, you can actually see it all in order. Copy and paste the information, and create a random key for the access tokens!

Now, provided you did it right, **you can now actually post tweets through "[http://sitenamehere….php?tweet=Tweet](http://sitenamehere.com/directoryhere/tweet.php?tweet=Tweet) here!"!** Isn't that exciting? Note that special characters such as # or @ doesn't work (Unless using the URL encoding)…which is rather important with Twitter, but we'll solve that.

We're actually going to integrate it with the game, now! Cool! Now, what we're going to do is simple. We're going to create a new internet control. I know, it's not the best solution, but it's the best I can think of at the moment. If you have a better suggestion, tell me! I can easily adapt it.

Anyway, press Ctrl + T. The Components dialog will open. Look for "Microsoft Internet Controls", and check it. After you press OK, it'll appear in the toolbar. Create a new WebBrowser control, and name it wbTwitter. I hid it off screen. You can put it on for aesthetics, I don't really care, neither does it matter. After that's done, add this into any module:

```

Public Sub PostTweet(ByVal Tweet As String)

Dim ReplacedTweet As String

' Here, we'll add all of the important encodings! There are a lot...bear with me!

ReplacedTweet = Replace$(Tweet, "/", "%2F")

ReplacedTweet = Replace$(ReplacedTweet, "#", "%23")

ReplacedTweet = Replace$(ReplacedTweet, "?", "%3F")

ReplacedTweet = Replace$(ReplacedTweet, "&", "%24")

ReplacedTweet = Replace$(ReplacedTweet, "@", "%40")

ReplacedTweet = Replace$(ReplacedTweet, "%", "%25")

ReplacedTweet = Replace$(ReplacedTweet, "+", "%2B")

ReplacedTweet = Replace$(ReplacedTweet, "~", "%&E")

ReplacedTweet = Replace$(ReplacedTweet, " ", "%20")

ReplacedTweet = Replace$(ReplacedTweet, ";", "%3B")

ReplacedTweet = Replace$(ReplacedTweet, "=", "%3D")

ReplacedTweet = Replace$(ReplacedTweet, "$", "%26")

ReplacedTweet = Replace$(ReplacedTweet, ",", "%2C")

ReplacedTweet = Replace$(ReplacedTweet, "<", "%3C")

ReplacedTweet = Replace$(ReplacedTweet, ">", "%3E")

ReplacedTweet = Replace$(ReplacedTweet, "^", "%5E")

ReplacedTweet = Replace$(ReplacedTweet, "`", "%60")

ReplacedTweet = Replace$(ReplacedTweet, "\", "%5C")

ReplacedTweet = Replace$(ReplacedTweet, "[", "%5B")

ReplacedTweet = Replace$(ReplacedTweet, "]", "%5D")

ReplacedTweet = Replace$(ReplacedTweet, "{", "%7B")

ReplacedTweet = Replace$(ReplacedTweet, "}", "%7D")

ReplacedTweet = Replace$(ReplacedTweet, "|", "%7C")

ReplacedTweet = Replace$(ReplacedTweet, vbQuote, "%22")

frmServer.wbTwitter.Navigate ("replace the link here to your AutoTweeter!" & ReplacedTweet), 4 ' Note the , 4! That stops the IE control

' from keeping a cache.

End Sub

```

And that's all to it, for now! **Don't forget to replace the link in frmServer.wbTwitter.Navigate to your own link, and change the API keys in the PHP code.** It all works perfectly fine, and I've tested it pretty well, so we'll see how it goes!

**Questions and Answers:**

**What is the FPS impact?**

For me, it was negligable. I tested it extensively, and it does not stop the thread of execution, so you do not need to worry about the server stalling. Obviously, if this does cause issues, simply remove it, and tell me any relevant info (specs, edits, etc.)

**Ohoh do Facebook!**

No, I hate that API with a passion.

Want any examples of functionality? See my next post.
Link to comment
Share on other sites

**Additional Functionality**

**~ Notifying when a member levels up ~**

In CheckPlayerLevelUp, you can Tweet when a player levels up. Directly before (Or directly after. Doesn't actually matter.):

```

SendEXP Index

SendPlayerData Index

```

You can add:

```

Call PostTweet(GetPlayerName(Index) & " has #leveled up to " & GetPlayerLevel(Index) & "!")

```

This'll post a tweet anouncement when a player levels up in your game.

More to come, soon!
Link to comment
Share on other sites

I thought you were going to use PHP sockets.

![:(](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/sad.png)

![:(](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/sad.png)

![:(](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/sad.png)
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...