Log in

View Full Version : Twitter / iTweet.net



Nli.
16-07-2009, 03:50 PM
Hi.

Well I've been looking on the Internet for a long time now and at the Twitter API. I'm trying to create a website like iTweet.net that will allow *anyone* to sign in with their Twitter ID and basically use twitter but through a different website if that makes sense, like; @replies, direct messages, status updates etc...

But I haven't been able to find a way yet. I'm wondering if anyone can help me out :) but some of you may just say look at the API and stuff, but I don't quite know what I'm looking for as I haven't really done this before, and I dunno it might be a big thing to do for a "first timer" but my School has filtered Twitter, and now have filtered iTweet, I want to create my own site with different features on so teachers won't realise. (like those proxys that some people have created) so we can carry on Tweeting :)

Thanks

Blob
16-07-2009, 04:26 PM
The twitter api has a few limitations though...


The default rate limit for calls to the REST API is 150 requests per hour. The REST API does account- and IP-based rate limiting. Authenticated API calls are charged to the authenticating user's limit while unauthenticated API calls are deducted from the calling IP address' allotment.

Nli.
16-07-2009, 04:41 PM
Thanks, just wondering how iTweet do it now. That's all (:

RichardKnox
16-07-2009, 09:05 PM
That's fine though as long as you don't update your twitter every 24 seconds?
Anyway, I would do it by using OAuth to sign in and then simply calling an OAuth object to (I think) http://twitter.com/statuses/update.xml and post that along with an array (I think it's like message => 'updating twitter').

I personally use the OAuth class that's linked to on the official twitter API page. If you want I can try showing you a bit more in detail but not right now as I have some work to finish up.

But simply:

authorize via OAuth -> set tokens etc -> call on the TwitterOAuth class using tokens -> use function in the class and post to update page

Fehm
16-07-2009, 09:54 PM
Only problem is, and this isnt a subject I have looked into, so enlighten me, but wouldnt it be possible to change someone else's twitter? =D Enlighten away?!

Excellent2
16-07-2009, 10:03 PM
What you will want to do is, download the Twitter API and then use cURL to connect to their server. Use XML to grab all the information you want and then let them reply.

RichardKnox
16-07-2009, 11:58 PM
What you will want to do is, download the Twitter API and then use cURL to connect to their server. Use XML to grab all the information you want and then let them reply.

Nah, because although Basic Auth is not being phased out yet it will happen eventually. OAuth is the way forward!

Nli.
17-07-2009, 03:54 PM
That's fine though as long as you don't update your twitter every 24 seconds?
Anyway, I would do it by using OAuth to sign in and then simply calling an OAuth object to (I think) http://twitter.com/statuses/update.xml and post that along with an array (I think it's like message => 'updating twitter').

I personally use the OAuth class that's linked to on the official twitter API page. If you want I can try showing you a bit more in detail but not right now as I have some work to finish up.

But simply:

authorize via OAuth -> set tokens etc -> call on the TwitterOAuth class using tokens -> use function in the class and post to update page

I have read about OAuth but I haven't read too much in to it.


What you will want to do is, download the Twitter API and then use cURL to connect to their server. Use XML to grab all the information you want and then let them reply.

When you say download the Twitter API? Is that the "Libraries"

I'm new at this sort of stuff, so yeah sorry if I dont get anything straight away.

Trinity
17-07-2009, 04:40 PM
That's fine though as long as you don't update your twitter every 24 seconds?
Anyway, I would do it by using OAuth to sign in and then simply calling an OAuth object to (I think) http://twitter.com/statuses/update.xml and post that along with an array (I think it's like message => 'updating twitter').

I personally use the OAuth class that's linked to on the official twitter API page. If you want I can try showing you a bit more in detail but not right now as I have some work to finish up.

But simply:

authorize via OAuth -> set tokens etc -> call on the TwitterOAuth class using tokens -> use function in the class and post to update page

I think I see a flaw in this method. Wouldn't using OAuth take users to the twitter.com/oauth/blabla first? So it wouldn't work, as twitter is filtered at his school.

Nli.
17-07-2009, 04:41 PM
Oh yeah, I forgot about that.
Because it takes you to the twitter page in order to click allow or deny.

Invent
17-07-2009, 05:09 PM
You could use basic HTTP auth or just authenticate using OAuth at home or something and store the tokens in a DB or whatever.

RichardKnox
17-07-2009, 05:14 PM
I think I see a flaw in this method. Wouldn't using OAuth take users to the twitter.com/oauth/blabla first? So it wouldn't work, as twitter is filtered at his school.

Smart haha. Working on that you probably couldn't even use basic auth then as if it's blocked I doubt you can cURL it.

Invent
18-07-2009, 10:53 AM
Smart haha. Working on that you probably couldn't even use basic auth then as if it's blocked I doubt you can cURL it.

If you cURL it then the request will be made on the server so it couldn't be blocked.

Excellent2
18-07-2009, 10:54 AM
If you cURL it then the request will be made on the server so it couldn't be blocked.Exactly my point.

RichardKnox
18-07-2009, 03:58 PM
Oh right fair enough. I just assumed, wrongly I may add, that it would be blocked.

Nli.
21-07-2009, 06:29 PM
I've made little progress from my last post but I found this code;


<?php
$twitter_username = 'TWITTER USERNAME HERE';
$twitter_password = 'TWITTER PASSWORD HERE';
$errno = 0;
$errstr = '';
$response = '';
function httpRequest($host, $path = '/', $method = 'GET') {
global $errno, $errstr, $response;
global $twitter_username, $twitter_password;
$header = "$method $path HTTP/1.1\r\n";
$header .= "Host: $host\r\n";
$header .= "Accept-Encoding: none\r\n";
$header .= "Authorization: Basic " . base64_encode("{$twitter_username}:{$twitter_password}") . "\r\n";
$header .= "Connection: Close\r\n\r\n";
$sock = fsockopen($host, 80, $errno, $errstr, 30);
if (!$sock) {
die("<p><strong>fsockopen() error:</strong><br />$errstr ($errno)</p>");
} else {
fwrite($sock, $header);
while (!feof($sock)) {
$response .= fgets($sock, 128);
}
fclose($sock);
$response = trim(str_replace(array('<', '>'), array('&lt;', '&gt;'), $response));
return true;
}
}
echo "<p>Contacting Twitter...</p>\n";
httpRequest('twitter.com', '/statuses/update.xml?status=Testing+Testing+1+2+3!', 'POST');
echo "<p>Response:<br /><hr /><pre>$response</pre><hr /></p>\n";
?>


I'm rubbish at explaining so sorry if any one gets confused.

If I edit the last few lines, that is what gets posted on to twitter, as I'm sure some of you would already be able to tell. This file requires me to edit the message at the bottom and then 'visit' the URL in order to post it.

For example, if I uploaded that above code to my localhost, I'd visit localhost/twitter.php and then this would appear;



Contacting Twitter...

Response:
HTTP/1.1 200 OKDate: Tue, 21 Jul 2009 18:27:40 GMTServer: hiLast-Modified: Tue, 21 Jul 2009 18:27:40 GMTStatus: 200 OKETag: "b363d4347d43725ea5d1c3ee0c63f8c8"Pragma: no-cacheCache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0Content-Type: application/xml; charset=utf-8Content-Length: 1722Expires: Tue, 31 Mar 1981 05:00:00 GMTX-Revision: a5c6210d770d282e091e8cae25fc5450b30f7a54X-Transaction: 1248200860-4861-14321Set-Cookie: lang=en; path=/Set-Cookie: _twitter_sess=BAh7CToJdXNlcmkEQxQDAToTcGFzc3dvcmRf dG9rZW4iLTk0YzAwYTQ0MzAw%250AYmI2ZjFmODNkZDZjZWNkN DA0ZDhlMmI5MGZlODg6B2lkIiVjMWY1M2Y3ZTAy%250AZDJmOD E2OTE5OWQzNDY4NTRkYmFhZSIKZmxhc2hJQzonQWN0aW9uQ29u dHJv%250AbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZ WR7AA%253D%253D--4ba6076345ffc1e6d9435db1252b14c823e4e579; domain=.twitter.com; path=/Vary: Accept-EncodingConnection: close<?xml version="1.0" encoding="UTF-8"?><status> <created_at>Tue Jul 21 18:21:25 +0000 2009</created_at> <id>2762283224</id> <text>Testing Testing 1 2 3!</text> <source><a href="http://apiwiki.twitter.com/">API</a></source> <truncated>false</truncated> <in_reply_to_status_id></in_reply_to_status_id> <in_reply_to_user_id></in_reply_to_user_id> <favorited>false</favorited> <in_reply_to_screen_name></in_reply_to_screen_name> <user> <id>16979011</id> <name>Craig Jones</name> <screen_name>CraiggJ</screen_name> <location>Dudley</location> <description></description> <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/318417751/abstract_brushes_2_normal.jpg</profile_image_url> <url></url> <protected>false</protected> <followers_count>109</followers_count> <profile_background_color>642D8B</profile_background_color> <profile_text_color>3D1957</profile_text_color> <profile_link_color>FF0000</profile_link_color> <profile_sidebar_fill_color>7AC3EE</profile_sidebar_fill_color> <profile_sidebar_border_color>65B0DA</profile_sidebar_border_color> <friends_count>116</friends_count> <created_at>Sun Oct 26 11:02:10 +0000 2008</created_at> <favourites_count>5</favourites_count> <utc_offset>0</utc_offset> <time_zone>London</time_zone> <profile_background_image_url>http://static.twitter.com/images/themes/theme10/bg.gif</profile_background_image_url> <profile_background_tile>true</profile_background_tile> <statuses_count>341</statuses_count> <notifications>false</notifications> <verified>false</verified> <following>false</following> </user></status>

Some of that looks promising, but I'm not sure how I would go about doing, what I'm trying to achieve, like using fields in order to post to that file so I wouldn't have to manually insert user details (username, password) and what I'd do next.

Sorry if I've confused some of you.

Nli.
22-07-2009, 06:34 PM
I'm not sure what the rules are for double posting so I waited 24 hours :)
So yeah, I wasn't sure what to do with the XML, how I would convert it sort of thing.
So whilst I was waiting for a reply or a idea to pop in to my head.

I just changed the code so I don't have to manually put the Twitter Name and Password in so I guess it's a type of login.

I read that the curl could be used but I'm not sure how that works because on websites I've seen it posted like;
curl --basic --user username:password --data status="Having fun with cURL" http://twitter.com/statuses/update.xml

It's all very confusing lol, but I think I'm learning slowly...

RichardKnox
22-07-2009, 06:38 PM
Just post the username, password and message to variables via a form and then use those variables to replace message, username and password things in the php.

Nli.
22-07-2009, 06:42 PM
<?php
$twitter_username=$_POST['login'];
$twitter_password=$_POST['passwd'];
$status=$_POST['status'];
$errno = 0;
$errstr = '';
$response = '';
function httpRequest($host, $path = '/', $method = 'GET') {
global $errno, $errstr, $response;
global $twitter_username, $twitter_password;
$header = "$method $path HTTP/1.1\r\n";
$header .= "Host: $host\r\n";
$header .= "Accept-Encoding: none\r\n";
$header .= "Authorization: Basic " . base64_encode("{$twitter_username}:{$twitter_password}") . "\r\n";
$header .= "Connection: Close\r\n\r\n";
$sock = fsockopen($host, 80, $errno, $errstr, 30);
if (!$sock) {
die("<p><strong>fsockopen() error:</strong><br />$errstr ($errno)</p>");
} else {
fwrite($sock, $header);
while (!feof($sock)) {
$response .= fgets($sock, 128);
}
fclose($sock);
$response = trim(str_replace(array('<', '>'), array('&lt;', '&gt;'), $response));
return true;
}
}
echo "<p>Contacting Twitter...</p>\n";
httpRequest('twitter.com', '/statuses/update.xml?status=Test+again!', 'POST');
httpRequest('twitter.com', '/statuses/public_timeline.xml', 'GET');
httpRequest('twitter.com', '/statuses/friends.xml', 'GET');
echo "<p>Response:<br /><hr /><pre>$response</pre><hr /></p>\n";
?>


That's what I have at the moment.
I tried editing the /statuses/update.xml?status= bit so it will display what was posted on the field and what's displayed at the top of the code. How would I convert the XML into something readable? Unless you don't lol.

Excellent2
22-07-2009, 06:47 PM
I read that the curl could be used but I'm not sure how that works because on websites I've seen it posted like;
curl --basic --user username:password --data status="Having fun with cURL" http://twitter.com/statuses/update.xml It's all very confusing lol, but I think I'm learning slowly...http://uk.php.net/curl

RichardKnox
22-07-2009, 08:12 PM
Nah, you'd do this:



httpRequest('twitter.com', '/statuses/update.xml?status='.$_POST['message.'', 'POST');

(for example)

Nli.
22-07-2009, 09:22 PM
Nah, you'd do this:



httpRequest('twitter.com', '/statuses/update.xml?status='.$_POST['message.'', 'POST');

(for example)

Unfortunatley that doesn't work.
But um I was searching the internet.
It works with three files, pretty short codes.
It converts the XML in to readable writing which is a step forward I guess, Just got to keep working with it :)

RichardKnox
22-07-2009, 10:55 PM
httpRequest('twitter.com', '/statuses/update.xml?status='.$_POST['message'].'', 'POST);


If you're posting a message to it that should work for updating it.

Nli.
22-07-2009, 11:06 PM
Hm what I did was, on a seperate HTML page I had a field where you could type in the status, and then it would post it to the page (where that code would be placed) like I did with the username and password - where it worked. I add that code and it gives an error.

Suspective
23-07-2009, 07:21 AM
Make sure its all legal.

Trinity
23-07-2009, 07:33 AM
Make sure its all legal.

...Why wouldn't it be?

Nli.
23-07-2009, 11:41 AM
Make sure its all legal.
Twitter wouldn't make a API for people to use and make things if it were illegal.

Want to hide these adverts? Register an account for free!