Tumblr API in PHP File structure - php

I'm trying to use the Tumblr API (PHP) and I cant seem to get all the required files to load correctly.
The Tumblr API can be found here: https://github.com/tumblr/tumblr.php
First thing I found out is that it doesnt include OAuth, so after some searching I found the files on github and uploaded them to my server.
Now it's saying it needs Guzzle. OK, got that uploaded now, but I cant seem to get all the Guzzle files to load up... Example error message:
Interface 'Guzzle\Common\HasDispatcherInterface' not found in /TumblrTest/Guzzle/Common/AbstractHasDispatcher.php
There's a HasDispatcherInterface.php file in that path...
Do the files need to be in a special order? I tried putting all .php files into a folder, and then using require_once I searched for all *.php files in that folder, but that didnt work...
Sorry for a super noob question, any help would be greatly appriciated! Let me know if there's any other info i need to give to help answer this question!
-D
UPDATE: I still have no idea how the above works, but I found a way around it... I actually think it might be easier then figuring the above out!! The following PHP code does what i need it to do, which is grab the posts of the provided user:
$apikey = **[insert api key here]**;
$limit = $_POST['limit'];
$user = $_POST['user'];
$tumblr=$user . ".tumblr.com";
$apidata = json_decode(file_get_contents("http://api.tumblr.com/v2/blog/$tumblr/posts/photo?api_key=$apikey&limit=$limit"));
$mypostsdata = $apidata->response->posts;
$myposts = array();
$j = 0;
foreach($mypostsdata as $postdata) {
$post["photo_url"] = $postdata->photos[0]->original_size->url;
$post["width"] = $postdata->photos[0]->original_size->width;
$post["height"] = $postdata->photos[0]->original_size->height;
$myposts[$j] = $post;
$j++;
}
echo json_encode($myposts);
For some reason I cant get it to pull a list of people i'm following and then get their posts, but oh well...

The tumblr.php Readme might be a bit confusing.
The package depends on other packages. All can be installed via composer.
Go to the http://getcomposer.org and read this carfully, if you are used to the concept, you will start rewriting all you classes to fit the composer dependency manager ;-)
to make it short:
install composer globally and
go into a blank directory and
type in your terminal
composer require tumblr/tumblr
you should get all the classes and the other projects in a dir called vendor.
before you do anything you need to require the autoload.php file.
And check out the concept of namespaces in php.

Related

Issue with third party Google Analytics sdk

I have code which works above the php 5
its actually GA Library, here is its github project.
I have cloned the project theiconic/php-ga-measurement-protocol
Since I am new to PHP, I have no idea where to put this code, Please help me here this project should be installed via composer via code
{
"require": {
"theiconic/php-ga-measurement-protocol": "^2.0"
}
}
After this step I need to create a file something.php and I need to put the code below, I am having problem on locating autoload.php on my server, Please look at the code below to understand what i am saying.
<?php
//grab the data that Calendly sent in the webhook and store it in a variable called $objCalendlySubmission...
$objCalendlySubmission = json_decode(file_get_contents('php://input'));
//We've passed the Google client_id in Calendly's placeholder for utm_term. Feel free to pass it differently, this is just an example
if(property_exists($objCalendlySubmission->payload->tracking, 'utm_term') && !empty($objCalendlySubmission->payload->tracking->utm_term)) {
$strPageViewed = 'calendly_conversion.html'; // We use different page names depending on what type of event was scheduled via Calendly
sendGoogleAnalyticsPageView($objCalendlySubmission->payload->tracking->utm_term, $strPageViewed);
}
function sendGoogleAnalyticsPageView($strGAClientId, $strURL) {
require_once '/path_to_composer/composer/vendor/autoload.php'; //loads the PHP library for the "Google Analytics Measurement Protocol” **I dont know where is it located exactly on my xampp server, Please guide me here**
$analytics = new TheIconic\Tracking\GoogleAnalytics\Analytics(true); //you may have to adjust this path based on your setup **please help me here**
$analytics
->setProtocolVersion('1')
->setTrackingId('YOUR-GA-UA-ID-GOES-HERE')
->setClientId($strGAClientId)
->setDocumentLocationUrl($strURL);
$analytics->sendPageview();
}
?>
In the above code towards middle line
require_once '/path_to_composer/composer/vendor/autoload.php'; //loads the PHP library for the "Google Analytics Measurement Protocol”
I dont know where is it located exactly on my xampp server, Please guide me here
$analytics = new TheIconic\Tracking\GoogleAnalytics\Analytics(true); //you may have to adjust this path based on your setup
Here is the image of Project folder
Project structure Part 2

How to use Httpful PHP Library

I'm trying to learn REST, and thought it might be good to start with a PHP REST client such as Httpful. I just can't seem to get it to work. I downloaded the httpful.phar file and placed it in my working directory. Then created a simple php file with the following contents from an example on the their site:
<?php
// Point to where you downloaded the phar
include('httpful.phar');
$uri = "https://www.googleapis.com/freebase/v1/mqlread?query=%7B%22type%22:%22/music/artist%22%2C%22name%22:%22The%20Dead%20Weather%22%2C%22album%22:%5B%5D%7D";
$response = Request::get($uri)->send();
echo 'The Dead Weather has ' . count($response->body->result->album) . " albums.\n";
?>
I've tried multiple examples on the site, but only get a blank page when I load it in my browser.
Thanks for any help you can give!
This library uses Namespaces. Either use a complete classname or use the class
With a complete Classname:
\Httpful\Request::get($uri)->send();
With a use:
use Httpful\Request;
Request::get($uri)->send();
The sample code sadly is very incomplete on the website, but you can get the hint from sample below topic "INSTALL OPTION 1: PHAR" or from the actual source code inside the phar.
http://phphttpclient.com/

Codeigniter: highlighting strings text in codeigniter

I tried to implement this(http://web.archive.org/web/20080506155528/http://software.zuavra.net/inline-diff/) with my codeigntier framework but i could not able to implement it.
Anyone if you have implemented this with codeigniter framework then please help me.
Why i could not able to implement:
I run those files seperately(Not with framework) & it worked for me. but while keeping the same files( i.e inline_example.php content) in my COdeigniter controllers then it showed me too many errors like(shown in image) . Then i though this is out of my capacity to implement with codeignter. so i thought to ask here help
i have implemented this library in codeigniter.
To resolve that error you have to replace &new variable to new in all library files of inline diff.
for example :
inline_function.php
$diff = &new Text_Diff($hlines1, $hlines2);
$diff = new Text_Diff($hlines1, $hlines2);
and also change path in unified.php and diff.php
require_once(APPPATH.'libraries/Text/Diff/Renderer.php');

php svn class svn_fs_make_dir ( resource $root , string $path )

I am trying to write a class to handle svn. Looking at php website looks like there are some functions already there but, have problem using them since not enough documentations.
Has anyone worked with svn_fs_make_dir ( resource $root , string $path )? if so what is "resource $root". I can't figure it out.
Does anyone know a good open source php class to deal with svn requests? I am doing a release management project and need to access svn within the code and create, copy,...
Thanks
At least phpsvnclient documented better, know nothing about it's quality

Errors when implementing WURFL with Zend

I've looked around and cant seem to find someone with the same issue as me, hoping i've not missed a clanger here.
I'm wanting to get device browser information for each user, i'm currently planning on doing this within the bootstrapper, following something i saw in PHP conference.
To that end i came across:
http://framework.zend.com/manual/en/zend.http.user-agent.html
Which explains how to install and use wurfl. I've followed the instructions and am coming up with the following exception:
Uncaught exception 'Zend_Http_UserAgent_Features_Exception' with message '"wurflapi" configuration is not defined'
My limited understanding of Zend leads me to think the issue is within configs/application.ini
I have the following:
resources.useragent.wurflapi.wurfl_api_version = "1.1"
resources.useragent.wurflapi.wurfl_lib_dir = APPLICATION_PATH "/../library/wurfl-php-1.1/"
resources.useragent.wurflapi.wurfl_config_file = APPLICATION_PATH "/configs/wurfl-config.php"
Where my wurfl-config.php looks like:
echo "Loaded";
die;
$resourcesDir = dirname(__FILE__) . '/../../data/wurlf/';
$wurfl['main-file'] = $resourcesDir . 'wurfl-latest.zip';
$wurfl['patches'] = array($resourcesDir . 'web_browsers_patch.xml');
$persistence['provider'] = 'file';
$persistence['dir'] = CACHE_ROOT . "/wurfl/";
$cache['provider'] = null;
$configuration['wurfl'] = $wurfl;
$configuration['persistence'] = $persistence;
$configuration['cache'] = $cache;
I'm expecting the script to die after priting loaded, but i'm not getting this, meaning the config isnt loading correctly.
Where might be the problem? What more information do you require? Has anyone else come across this dilemma before?
Thanks in advance
Seems that you're unable to do what i want.
In that this doesnt seem to want to work within a bootstrap. Instead you should do this as a plugin.
This video tutorial helps explain the documentation a little better:
http://mcloide.wordpress.com/2010/12/08/mobile-development-with-zend-framework-and-wurfl/
Now that i have setup the plugin i dont get the exception and my config loads perfectly. Humpf!!

Categories