pulling mentions from twitter with php - php

I am trying to retrieve mentions from twitter using php. The current code I have works fine to retrieve the user_timeline, however when I try to use the same code for the mentions I get an authentication error. What is the best way to retrieve mentions with userid, pictures, text, etc included?
if I change user_time to mentions I get an authentication error.
Here is the code I use now to retrieve user_timeline with php.
<?php
$xmldata = "http://twitter.com/statuses/user_time/usernid.xml";
$open = fopen($xmldata,'r');
$content = stream_get_contents($open);
fclose($open);
$xml = new SimpleXMLElement($content);
$screenname = $xml->status[0]->user->screen_name;
?>

You have to use OAUTH ("Returns the 20 most recent mentions (status containing #username) for the authenticating user."):
https://dev.twitter.com/docs/api/1/get/statuses/mentions
Try: https://github.com/abraham/twitteroauth or http://www.joeyrivera.com/2010/twitter-api-oauth-authentication-and-zend_oauth-tutorial/ and https://dev.twitter.com/apps/new

Related

Get youtube channel ID from website

I have the below code for retrieving views and subscribers from a YouTube channel "?q=dsagov"
$UserID = $_GET['q'];
$data = file_get_contents('http://gdata.youtube.com/feeds/api/users/'. $UserID.'');
$xml = new SimpleXMLElement($data);
$stats_data = (array)$xml->children('yt', true)->statistics->attributes();
$stats_data = $stats_data['#attributes'];
echo 'Views = '.$stats_data['subscriberCount'].'<br />';
echo 'Subscribers = '.$stats_data['totalUploadViews'].'<br />';
I would like to take this one step further and find the YouTube channel ID based on a website address, in this case https://www.gov.uk/government/organisations/driving-standards-agency .
So either REGEX the website find the Channel ID or another method which I am not aware of using YouTube API, I can put the URL of the website and have it find the official channel is this possible?
Thanks in advance.
Just to clarify
For example I would like to enter a URL in query "/?q=gov.uk/government/organisations/driving-standards-agency" what the script would do is find the YouTube Channel ID on the URL and run the API and display the results
I don't think this is possible.
Where would you search for website name ? This could be in user's descriptions, video descriptions, many more places for many users and videos.

PHP: file_get_contents function does not work in graph api facebook

I am trying to retrieve facebook uesr ID via graph from below code
$post = "https://graph.facebook.com/me?access_token=".$access_token;
$response = file_get_contents($post);
I get the following error:
Warning: /me cannot be read [file_get_contents] https://graph.facebook.com/me?access_token=AAIvGrJsBAI3nLAbfaqyh8NExN5e21yKCvJAjVOGJ9ira1RdCDHRFszktHnDCY44urQtxdBHMKEsX1K7QAUWXSYF5ip3l68JI8xKeopjYdssds
But when i try to access the above graph URL via browser, its working correctly. So my access token is valid.
Note: I am using google app engine so I can't use cURL.
Use cURL or this class: http://ideone.com/Q1Zfl
I've used this class many times and it behaves well.
Usage:
$url = '...';
$req = new Request($url);
$data = $req->DownloadToString();
P.S I hope the link does not expire
You can use
$content = #file_get_contents($site);
To hide the error. If it's dont work. You go to the ini.php file and find the line
Allow_url_fopen = Off
Change "off" to "on"
Allow_url_fopen = On

Using PHP-SDK to get the album details

I'm tried get the details of an album using the PHP-SDK and facebook class, using the following code:
$data = $facebook->api('me/albums');
the code above return an empty array.
But if I try get the friends:
$friends = $facebook->api('/me/friends');
works fine. Why? the permissions are same.
in 'pure' mode:
$url = "https://graph.facebook.com/me/albums/?access_token={$_SESSION['access_token']}";
$res = curl($url);
$json = json_decode($res);
too works fine.
to get the alubms details of the currently logged-in user, you need to request for the "user_photos" permission too.
You have to have "user_photos" permission to access this resource.
Make sure the access_token you are using takes care of that.

trying to fetch user tweet stream in php

I am using the following code, but it showing a 404 error
$url = "http://api.twitter.com/version/statuses/user_timeline.json";
$call = file_get_contents($url);
There's no 'version' version. The Twitter API is currently version 1, so you need http://api.twitter.com/1/statuses/user_timeline.json.
Do note that Twitter can't read your mind, so you'll need to tell Twitter which user's timeline you want to fetch... i.e. http://api.twitter.com/1/statuses/user_timeline.json?screen_name=ceejayoz

Specifying Parameters in Zend_GData when using an Oauth Token?

So, I figured out how to get an access token from Google using the Zend_Oauth library in 1.10. Now lets say I want to get my contacts...
$config = array(
'consumerKey' => 'zzz',
'signatureMethod' => 'HMAC-SHA1',
'consumerSecret' => 'xxx'
);
$token = unserialize($_SESSION['GOOGLE_ACCESS_TOKEN']);
$client = $token->getHttpClient($config);
$client->setMethod(Zend_Http_Client::GET);
// $client->setParameterGet('max-results', '10000');
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full');
// $query->MaxResults=100;
$feed = $gdata->getFeed($query);
$feed is a lovely object with 25 contacts. But if I want to get more in a single pull, there doesn't seem to be a way of specifying max results that works.
If I uncomment client->setParameterGet it's ignored. It works if I specify $client->setUri and use $rawdata = client->request() to get the response, but then other issues crop up with handling the feed data that comes back... like getting it into GData for easy handling.
I've tried $feed = $gdata->importString($rawdata->getBody()) but while $rawdata->getBody() returns what seems to be valid XML, $feed->totalResults throws an error, while it wouldn't if I used $gdata->getFeed($query).
If I uncomment $query->MaxResults=100; use $gdata->getFeed($query) Google returns a 401 with "Unknown authorization header".
So is it possibly to specify parameters while using Zend_GData with an Oauth token? Or am I going to have to build my own requests, then use Zend_Feed (or some other XML/Feed dissector) for parsing?
I totally cannot get the whole list of contacts only 25... parameters do not seem to work using Gdata and query like this:
$http = $token->getHttpClient($oauthOptions);
$gdata = new Zend_Gdata($http, 'MY APP');
$gdata->setMajorProtocolVersion(3);
$gdata->getHttpClient()->setRequestScheme(Zend_Oauth::REQUEST_SCHEME_QUERYSTRING);
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full?max-results=10');
$query->setMaxResults(10);
$query->maxResults = 10;
$feed = $gdata->getFeed($query);
so i;m really into finding answers here as well. If either of you gets anything working. please post :-)
thanks
It's a bit tricky mixing a process meant to work with AuthSub with OAuth. I did some digging. So far I can get it to download all my contacts like this...
$client = $token->getHttpClient($config);
$client->setMethod(Zend_Http_Client::GET);
$client->setUri('http://www.google.com/m8/feeds/contacts/default/full/');
$client->setParameterGet('max-results', '10000');
$client->setParameterGet('v','3');
$bfeed = $client->request();
Looks like the primary difference between us is I specify the Feed URL in the $client->setUri('http://www.google.com/m8/feeds/contacts/default/full/'); and set my version differently. But I can get the body() property of $bfeed and it gives me 245k of XML to dissect.
My problem is that when I'm pulling down a single contact's feed via this method, I was getting an error.
I, like you, am trying to figure this out, so please reply with anything that works for you.

Categories