I'm using the BLogger API (google) to try and search for certain strings (i.e.'John Doe is my friend' - and return the blog id/url/etc) on public blogs. All I have found until now returns only data for my own account, not all public accounts.
Here's what I have now, it doesn't output much as I have no blogs set up myself. I've tried adding parameters and such to narrow down the search, but I feel the $query will need to change a bit.
<?php
$user = 'xxxxxx';
$pass = 'xxxxxx';
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Feed');
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'blogger', null,
Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null,
Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, 'GOOGLE');
$gdClient = new Zend_Gdata($client);
function printAllBlogs(){
$query = new Zend_Gdata_Query('http://www.blogger.com/feeds/default/blogs');
$feed = $gdClient->getFeed($query);
printFeed($feed);
}
function printFeed($feed){
$i = 0;
foreach($feed->entries as $entry) {
print $i ." ". $entry->title->text . "\n";
$i++;
}
}
?>
I figure this shouldn't be too crazy...just haven't found a solution yet. Thanks!
You say you're using the Blogger API, but for searching blogs you should use the Blog Search API, i think.
EDIT: It's only for Javascript, apparently...
Related
I've been trying to get the latest status back from a user's twitter feed using Abraham Williams' Twitter Oauth Library (https://github.com/abraham/twitteroauth) I followed the tutorial found at http://www.webdevdoor.com/php/authenticating-twitter-feed-timeline-oauth/ and created the get_tweet.php file as my index. When I run this on my website an all white page, with "null" in the top left corner is displayed.
As far as I am to understand my Oauth keys I have are valid, I am using 000webhost.com to host my website, my webserver is using PHP 5.2.17 and cURL is enabled, From the tutorial and sample files I have been using my index file should be correct, my website can be found at http://authortryndaadair.site90.net where the results of this call is being dispayed.
I have been able to troubleshoot a small amount, but I am unsure of what else could try to get this Api call working. Any help in solving this problem would be much appreciated.
Below is the contents of the index file substituting for get_tweet1.1.php:
session_start();
// Path to twitteroauth library
require_once("twitteroauth/twitteroauth/twitteroauth.php");
$twitteruser = "JaneSmith";
$notweets = 10;
$consumerkey = "123456";
$consumersecret = "789123";
$accesstoken = "456789";
$accesstokensecret = "1023456";
function getConnectionWithAccessToken($cons_key, $cons_secret,
$oauth_token, $oauth_token_secret) {
$connection = new TwitterOAuth($cons_key, $cons_secret,
$oauth_token, $oauth_token_secret);
return $connection;
}
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret,
$accesstoken, $accesstokensecret);
$tweets = $connection->get(
"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name="
. $twitteruser . "&count=" . $notweets
);
echo json_encode($tweets);
Assuming you are running the latest TwitterOAuth code the get line should look like this.
$tweets = $connection->get(
"statuses/user_timeline",
array("screen_name" => $twitteruser, "count" => $notweets)
);
Now I load the tweets from twitter by using a username like this: (keys and tokens are filled in my code)
<?php
session_start();
require_once("twitteroauth/twitteroauth.php"); // PATH TO TWITTEROUTH LIBRARY
if(isset($_GET['twitteruser']) && !empty($_GET['twitteruser'])) {
$twitteruser = $_GET['twitteruser']; // USER
}
$notweets = 60; // NUMBER OF TWEETS
// OAUTH SETTINGS APPLICATION (https://dev.twitter.com/apps/)
$consumerkey = "";
$consumersecret = "";
$accesstoken = "";
$accesstokensecret = "";
function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
$connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
return $connection;
}
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);
$data = json_encode($tweets);
?>
As you can see I load the tweets with a username and set the number of tweets.
Can this easily be changed to load tweets with a search term?
I've search on google but strangely I can't find much.
I've found this in the twitter API but that doesn't seem to work ..
https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames&since_id=24012619984051000&max_id=250126199840518145&result_type=mixed&count=4
source: https://dev.twitter.com/docs/api/1.1/get/search/tweets
(I changed the link to that link)
But I get this output with a var_dump:
string(319) "{"statuses":[],"search_metadata":{"completed_in":0.004,"max_id":2.50126199841e+17,"max_id_str":"250126199840518145","query":"%23freebandnames","refresh_url":"?since_id=250126199840518145&q=%23freebandnames&result_type=mixed&include_entities=1","count":4,"since_id":2.40126199841e+16,"since_id_str":"24012619984051000"}}".....
The Twitter search API only returns tweets from the past week or so. See more info here.
The Search API is not complete index of all Tweets, but instead an index of recent Tweets. At the moment that index includes between 6-9 days of Tweets.
Note that the search feature on Twitter's website does query historical tweets, it is just the API that does not support them.
I'm trying to get a youtube video from the $username with $tags:
$tags='detskij-sad-198';
require_once('Zend/Loader.php');
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$authenticationURL = 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = 'Schoolkharkovua',
$password = '*****',
$service = 'youtube',
$client = null,
$source = '*****',
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$devkey = '*****';
$yt = new Zend_Gdata_YouTube($httpClient, '', '', $devkey);
$yt->setMajorProtocolVersion(2);
$query = $yt->newVideoQuery();
$query->setMaxResults(4);
$query->setVideoQuery($tags); // also i tried $query->category = $tags;
$query->setAuthor($username);
$videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));
$videoFeed returns no entry, although I know that the $username has a video with $tags and this code to work until mid-March
If I do query only by the $username or by $tags - I get the result.
What am I doing wrong?
PS. http://gdata.youtube.com/demo/index.html return empty video feed too if I trying query by "Keywords" and "Author name" simultaneously
Hhhhhmmmmm.... It seems that "google" no longer get the symbols "-" in tags
But
echo 'Tags: ' . implode(", ", $videoEntry->getVideoTags());
still emty, youtube api don't return video tags!
Guys help me get video tags from my video channel, please!
You need to authenticate your connection, YT returns an empty media$keywords object now (as of last Aug).
https://developers.google.com/youtube/2.0/developers_guide_php#Authentication
and here's their blog post about it...
http://apiblog.youtube.com/2012/08/video-tags-just-for-uploaders.html
I've got my session with the valid token that i set up this way :
$session_token = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
// Store the session token in our session.
$_SESSION['cal_token'] = $session_token;
Then i want to be able to do this:
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$docs = new Zend_Gdata_Docs($client);
$feed = $docs->getDocumentListFeed();
But using the token. Instead of the authentication with user/pass/service
I already looked at some example of this but i didn't find any way to make it work.
Thank you everyone!
// Retrieve user's list of Google Docs
$client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['cal_token']);
$docs = new Zend_Gdata_Docs($client);
$feed = $docs->getDocumentListFeed();
foreach ($feed->entries as $entry) {
echo "$entry->title\n";
}
Google has chanced some things with their calendar API, and now I need to fix some strange symbols that are adding themselves to text. I found this thread which exactly describes the issue I'm dealing with:
http://www.google.com/support/forum/p/Calendar/thread?tid=25ac3d762b235a51&hl=en
The solution is to append "&hl=en" or "?hl=en" to the end of my 'basic' URL feed.
I'm confunsed how to do that though, because I am retrieving the feed as an object with Zend_Gdata:
<?php
// load library
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Http_Client');
// create authenticated HTTP client for Calendar service
$gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$user = "xxxxx";
$pass = "xxxxx";
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
$gcal = new Zend_Gdata_Calendar($client);
$query = $gcal->newEventQuery();
$query->setUser('xxxxx#group.calendar.google.com');
$secondary=true;
$query->setVisibility('private');
$query->setProjection('basic');
$query->setOrderby('starttime');
$query->setSortOrder('ascending');
//$query->setFutureevents('true');
$startDate=date('Y-m-d h:i:s');
$endDate="2015-12-31";
$query->setStartMin($startDate);
$query->setStartMax($endDate);
$query->setMaxResults(30);
try {
$feed = $gcal->getCalendarEventFeed($query);
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getResponse();
}
?>
I tried to do this with no luck:
$query->setProjection('basic?hl=en');
Note: I've not used any of this before so I apologize if this doesn't work :)
The documentation says that getCalendarEventFeed() can take a URL as the parameter.
So we can change this...
$feed = $gcal->getCalendarEventFeed($query);
... to this in order to add the parameter to the query string:
$eventUrl = $query->getQueryUrl() . '?hl=en';
$feed = $gcal->getCalendarEventFeed($eventUrl);
Obviously, this is a simplified example - you should still perform the following two checks:
Make sure $query is an instance of Zend_Gdata_Query before calling getQueryUrl() on it.
Ensure that there are no other query parameters already added to $eventUrl so that we can use &hl=en rather than ?hl=en. You could probably use Zend_Uri for this.