PHP class or library to allow tweeting from a website - php

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.

Related

Twitter oembed for timelines?

Hi I use the following code to embed tweets but I am wondering if there is away as simple as the following to embed user profiles, I can't seem to find it on dev.twitter.com they keep taking me to make a widget. which is what I want to do but I want them to do it on request of the PHP
Currently i use something like this. But as you can see from below it only gets the status and not the timeline of the user.
$status = file_get_contents("https://api.twitter.com/1/statuses/oembed.json?url=".$links[$j]);
$stats = json_decode($status);
//$string = "https://api.twitter.com/1/statuses/oembed.json?url=".$links[$j];
if(isset($stats->errors))
{
}
else
$string=str_replace($links[$j],''.$links[$j].'',$string).$stats->html;
}
You can't get the html of users timeline, like you are getting it for status.
There is no end point with oembed available for users profile.
But you can easily build it yourself by following these steps.
Register an application
Get the API keys and access token
Use some library for PHP from these listed in this page Twitter Libraries, I would prefer going with the abraham's library
Get the user details by making request to this URL:
https://api.twitter.com/1.1/users/show.json?screen_name=[screen_name]
*Note: Twitter API v1 is deprecated so use API v1.1 for making requests
Fetch the JSON response and render it in your html code

Get facebook posts/events/news/gallery with javascript (or php) inside my website

I'm tryin to develop a (almost) 100% client-side dynamic website by integrating it with twitter, facebook and flickr.
I've been able so far to get the last 4 tweets (with javascript) from my client's feed, and now i was wandering if i could do the same with facebook's gallery and events from their feed.
Especially, what i need (given the facebook username/api key/whatever)
gallery
for each gallery in user's profile:
get the gallery name
get the first picture
get the gallery url
news/events
for each news/event/post in user's profile:
get the event name
get the event text
get the event picture (if provided)
get the event url
I don't want to use the facebook widgets with their rendering, i just need to read the json response (if there's any) and put the data inside my website (like a preview).
Since my client is pretty rusty with "computers (cit.)" but he's (not so strangely) comfortable with facebook/twitter/flickr, i tought about a solution like this before adding a database and an admin interface to our website.
I found some resources online, so i think it's possible (in a way or another). I'd like to do it in javascript, but if it's php i won't complain.
Check out this API to get photoes from the user profile
http://developers.facebook.com/docs/reference/api/album/
This is for events
http://developers.facebook.com/docs/reference/api/event/
You can use either the PHP or the Javascript API SDKs:
http://developers.facebook.com/docs/reference/php/
http://developers.facebook.com/docs/reference/javascript/
respectively. Naturally you would handle the returned information differently. Both have a method called api() which can be utilised to grab the album and event objects (as mentioned in another answer):
http://developers.facebook.com/docs/reference/api/album/
http://developers.facebook.com/docs/reference/api/event/
You can pass parameters in the methods to restrict the results returned by fields, number of items, sizes of images etc. This is outlined here:
http://developers.facebook.com/docs/reference/api/
But the issues you are going to face is that you have to authorise your "app" - think website when they use the terminology "app" - to give it permissions to access the information. This takes the form of a two step process. You have to create the app on the Facebook platform which can then access the API methods (only certain information can be got from the API methods without an authenticated app).
The second part is that the user themselves must then authenticate their facebook account against your app - this gives your app permission to access the user's information. In plain English it would go like this:
User visits your webpage; user must be logged into Facebook and must approve your app (this used to be called Facebook Connect for obvious reasons); the app and the user account are "connected"; the app can then use the api methods you've written to return information about the connected user
The beginning explanations of how to do this are here:
http://developers.facebook.com/docs/authentication/
The only way you can access a user's (non-public) information from outside of Facebook is via a connected app and user profile.

upload into my soundcloud account using my web form and api?

I'm creating a mobile application which plays music stored in my SoundCloud account.
Is there any way to create an automatic login to my SoundCloud account (PHP)? I don't want each user to have to use OAuth because it is only accessing my account and they will have already logged into my site.
Basically i just want to have a list of users tracks, and have the users be able to add or delete tracks from this account with my web form.
All the documentation I've seen uses OAuth to log into individuals accounts but i only want to access my account.
any help or a direction to look would be great
thanks
I was able to login in to a soundcloud account programmatically in PHP using the undocumented (in PHP as yet!) credentialsFlow function:
$sc_client_id = "Client ID from the developer page on soundcloud for your app";
$sc_secret = "Client Secret from the developer page";
$sc_user = "your soundcloud account user";
$sc_pass = "your soundcloud account password";
// create client object and set access token
$client = new Services_Soundcloud($sc_client_id, $sc_secret);
// login
$client->credentialsFlow($sc_user, $sc_pass);
Then you can upload audio files using the $client variable, e.g. this code, taken from 'Uploading Audio Files', http://developers.soundcloud.com/docs#uploading
// upload audio file
$track = json_decode($client->post('tracks', array(
'track[title]' => 'This is my sound',
'track[asset_data]' => '#/absolute/path/to/file.mp3'
)));
// print track link
print $track->permalink_url;
Here's my suggestion: have your users create individual SoundCloud accounts for themselves, then create an interface that allows them to share individual tracks with you, which you can then aggregate into a playlist of some sort (which could then be streamed to whatever device you wish, via SoundCloud).
This has the following advantages:
You maintain control of your own personal SoundCloud account and don't have to worry about it expanding to an unmanageable size.
You have the ability to moderate tracks, allowing you to screen for copyrighted or troll content.
It's more extensible -- if you use something like Drupal's aggregate facility, or a plugin like FeedWordPress (not sure what your CMS platform is, if any), the RSS feeds of tracks you're using can also be taken and used elsewhere by your users, thus potentially increasing the size of your audience. I.e., a widget that displays the latest tracks people can drop onto social profiles or blogs or whatever.
If set up well enough, your solution might be able to encompass non-SoundCloud streaming sources -- YouTube, etc.
Basically, you're dumping links sent to you into an RSS feed, which are super easy to work with both cross-browser and cross-OS. I'd personally use Drupal for this, but I'm sure there are ways to do this just as easily in Joomla!, WordPress or any other CMS worth its salt.
Looks like you can parse the track data in JSON format
http://api.soundcloud.com/tracks?client_id=#{client_id}&limit=10&format=json
There's no "login" either. You're just grabbing a user's public tracks.
Soundcloud has a whole developer API that you should probably brush up on.

# mentions on Facebook using Facebook Connect API

I am trying to do # mentions on Facebook using either facebook.stream.publish or facebook.users.setStatus.
You are able to do this on Facebook and I know its possible to do using 3rd party APIs as a "Twitter Sync" app currently supports it.
So far I have tried using: #[fb_id], #:fb_id, #[fb_id:fb_name], #:[fb_id:fb_name] and #:[fb_id] in the stream message.
I know Facebook.com uses #[fb_id:fb_name] on the site.
I also know Facebook's Dashboard API uses #:fb_id
I am also willing to emulate this functionality on my end if someone knows how to insert an url into the user's status or stream with custom link text or some method of inserting FBML into the stream (<fb:name>)
Note:
fb_id = Facebook User ID
fb_name = Facebook User Name
example: #[552192373:Jason Boehm]
I am currently using Facebook's Offical PHP API Client.

What is the simplest way to add Facebook Connect to a PHP web site?

Facebook Connect
I have spent a few weeks putting together a basic web site which uses Facebook connect as authentication.
I have studied 'theRunAround', the provided example application. However the code is convoluted and uses a large number of files and classes, most of which have a lot of functionality that I have no need for. I have also had a good read of the documentation.
My code works almost all the time. However, occasionally I receive strange, unpredictable errors.
Required Features
Check if user is already logged in to Facebook, if so, retrieve the fb_uid, name, profile pic
Return a list of friends which have also connected to this application
Are there any tutorials, better than the ones provided by Facebook regarding such simple functionality?
I wrote my own library to work with Facebook Connect as I found the one provided to be very lacking.
I can't provide the code as it is company code, but here's a breakdown of what I needed to do. Hopefully you can use it and fill in the blanks easily yourself.
In your application settings, configure the "Connect" tab. The "Connect URL" in my case is the root folder where my xd_receiver.htm file is. Also, under "Advanced" I marked my app as a Web Application.
Put your xd_receiver.htm file in the root folder specified above. There is a ton of documentation on xd_receiver.htm out there. This is what facebook hits when the user logs in. It will write cookies to their browser which your application can read in later to do authentication.
The cookies Facebook sets are in the format of _ where APIKEY is your apps API key and is the name of the cookie. You'll need the _session_key cookie to make further API calls. If this cookie is not set, you need to show the login button as desscribed in steps 4 - 6. Otherwise skip to step 7.
You need to load in the Facebook javascript file on your page that you will have the FB login button. ==> http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php
To show the FB login button, use:
The Facebook JS will automatically render a facebook login button for you. It will trigger the "facebook_onlogin" method that you shall define once the user is logged in so you can do something after they login.
Right below the above markup, you need to call the FB init javascript to have it render the button:
FB.init('YOUR API KEY HERE', 'ABSOLUTE PATH TO YOUR XD_RECEIVER.HTM FILE HERE');
Use the session_key as set in the cookie to make any API calls. How to make API calls is well documented.
Hope this helps.
I have recently added a friend notification feature to Cogenuity using the facebook connect technology.
First, you need to create the facebook object in your php code. I am assuming that you have already done the facebook application registration goodness. I found a lot of the parts to facebook connect not to work but what did work was this.
$user = $facebook->require_login();
I found that the FQL parts worked pretty good.
$query = "select uid1 from friend where uid2 = {$user}";
$results = $facebook->api_client->fql_query($query);
I used this FQL query which may serve your needs.
$query = "SELECT name, pic_square, status, about_me FROM user WHERE uid = {$uid}";
$results = $facebook->api_client->fql_query($query);
As does the notification_send method.
$facebook->api_client->notifications_send($notifyTarget, $intro, 'user_to_user');
I hope this helps.

Categories