I know there are quite a few libraries out there that that allow Twitter to be integrated into a website. But I haven't yet found what I am looking for (or maybe my understanding of twitter API is lacking). I want to be able to tweet events that occur on my website - BUT in addition, I want to be able to add tweeted from www.example.
For instance, when I send tweets from my blackberry or iphone (or indeed from some other sites), underneath the tweet, there is a message that says, tweeted from (for example blackberry). Does anyone know of a PHP library or class that allows me to send tweets but also with a kind of 'signature' that says where the tweet was sent from?
Edit
Additionally, I want users to be able to tweet from my website. When they tweet, I would like the tweet to say that where it came from (for example, like it does for blackberry phones etc, as I described above).
It is not clear to me whether I still need a PHP application for this requirement, and also how to implement it. Do I need an additional library for allowing users to tweet from my website?
Note: my users do not log into my website using a twitter login, so my website does not have access to a users Twitter username开发者_运维问答/password etc.
First you must register an app at http://twitter.com/apps, then you can use this twitter class -> http://classes.verkoyen.eu/twitter_oauth
I wrote a tutorial on how to do this http://blog.cmstutorials.org/reviews/general/how-to-update-your-twitter-status-using-php , just follow the steps and you should be good to go
edit: how to include a link
you can write function to get a shortened url because you only have 140 charachters you can then use this function:
function getBitlyUrl($url)
{
$bitlylogin = 'your login name';
$bitlyapikey= 'your api key';
$bitlyurl = file_get_contents("http://api.bit.ly/shorten?version=2.0.1&longUrl=".$url."&login=".$bitlylogin."&apiKey=".$bitlyapikey);
$bitlycontent = json_decode($bitlyurl,true);
$bitlyerror = $bitlycontent["errorCode"];
if ($bitlyerror == 0) {
$bitlyurl = $bitlycontent["results"][$url]["shortUrl"];
}
else $bitlyurl = "error";
return $bitlyurl;
}
then just call it like this:
$url = getBitlyUrl('yourlink');
you can then just add $url
to your tweet
You need to create an application in twitter. And tweet via that application (using API) on twitter. the 'via XYZ' will be automatically added.
http://www.twitter.com/apps
You need to register an application at http://dev.twitter.com
(There you can also set information for "tweeted by" or your page url)
Afterwards you can use a library from the list here:
http://dev.twitter.com/pages/libraries#php
like https://github.com/abraham/twitteroauth or https://github.com/basilbthoppil/oauth_twitter (It has to support the oauth authentication system I think some of the librarys on the twitter page are outdated)
When you create an instance of the library in your php script you have to pass your authentication tokens to the constructor (how you do this varies from library to library so just read the docs).
Any tweet posted by using the library will contain your "tweeted by" etc. information.
精彩评论