LyricAPI - how to get full lyrics? - php

I want to use LyricAPI hosted on Wikia to get lyrics of songs. But in response I get only part of lyrics:
Await the coming storm, behold the sign in the sun
Chaos upon us spawn! The arrows of time pinpoints us all
Oh, well the maddening laughter growing louder with the memories
Atoms like incense rising, like a thousand candles al[...]
How can I get entire lyrics?
Here is my code:
$client = new SoapClient("http://lyrics.wikia.com/server.php?wsdl", array(
'username' => LYRIC_LOGIN,
'password' => LYRIC_PASS
));
$auth = array(
'username' => LYRIC_LOGIN,
'password' => LYRIC_PASS
);
$header = new SoapHeader('NAMESPACE','Auth',$auth,false);
$client->__setSoapHeaders($header);
$song = $client->getSOTD();

http://api.wikia.com/wiki/Documentation
For legal reasons, the API is not allowed to provide full-lyrics at
the moment. It currently provides a fair-use sample (to verify that
the match is correct) and a link to the page where the full lyrics can
be viewed.

Related

Active Collab API: How to get projects

I'm trying out the ActiveCollab API for my first time. I had to use StackOveflow to figure out how to get the API token since the docs don't tell me this.
Below is my code:
/* GET INTENT */
$url = 'https://my.activecollab.com/api/v1/external/login';
$fields = array(
'email' => "email#email.com",
'password' => "****"
);
$intent = curl_post_connector($url, $fields);
$intent = $intent->user->intent;
/* GET TOKEN */
$url = 'https://app.activecollab.com/my_app_id/api/v1/issue-token-intent';
$fields = array(
'intent' => $intent,
'client_name' => 'My App Name',
'client_vendor' => 'My Company Name'
);
$token = curl_post_connector($url, $fields);
$token = $token->token;
Everything above works and get's the token properly. What I find really weird is that I have to use API v1 to get this, and the docs on ActiveCollab's site don't mention any URL for API v5. It seems like this is the approach everything is taking here on StackOverflow.
Now with the token, I try to get my list of projects:
/* GET PROJECT */
$url = 'https://app.activecollab.com/my_app_id/api/v1/users';
$headers = array (
"X-Angie-AuthApiToken" => $token
);
$projects = curl_get_connector($url, $headers);
var_dump($projects);
But this does not work. There is no error returned - it instead returns an array of languages for some reason! I don't want to paste the massive json object here, so instead I'll link you to a photo of it: https://www.screencast.com/t/7p5JuFB4Gu
UPDATE:
When attempting to use the SDK, it works up until I try getting the token (which is just as far as I got without the SDK). I'm getting Server Error 500, and when looking at the logs, it says:
/home/working/public_html/ac/index.php(21): ActiveCollab\SDK\Authenticator\Cloud->issueToken(123456789)
#1 {main}
thrown in /home/working/public_html/ac/SDK/Authenticator/Cloud.php on line 115
This is line 115 of Cloud.php:
throw new InvalidArgumentException("Account #{$account_id} not loaded");
I honestly don't think I did anything wrong... there must be something wrong with my account ID.
Just for kicks, I commented out that line, and the error disappears and the page loads fine - except now I have no token...

Only get single translation from Google Translate API

So I'm using the Google Translate API in PHP as explained in the documentation...
require 'vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=src/i18n-php/credential.json');
use Google\Cloud\Translate\TranslateClient;
$g_tr = new TranslateClient([ 'projectId' => 'my-project' ]);
$source_language = "en";
$target_language = "de";
$text_to_translate = "Last name";
$result = $g_tr->translate($text_to_translate, [
'source' => $source_language,
'target' => $target_language,
]);
echo $result['text'];
This works just as expected until there are several translation possibilities, like in the above code example, where the German translation can either be "Familienname" or "Nachname" - The Google Translate API outputs both into the $result['text'] seperated by comma: Familienname, Nachname.
I've been searching my fingers sore looking for a way to only get a single (preferably the most popular) translation. What do I have to do so that I only get one single translation possibility back from Google?

How to get Google Adwords ad cost over time with PHP?

So I have successfully established an ouath connection with Google Adwords, but I fail to realize how a request should look like in order to get the ad cost over time. What parameters should I use?
I was hoping to find a more simple solution, like the api calls made to Google Analytics:
public function getAudienceMetricsAll($google_analytics_account_id)
{
$curl = new Curl("https://www.googleapis.com/analytics/v3/data/ga");
$curl->setParams([
"ids" => "ga:" . $google_analytics_account_id,
"dimensions" => "ga:date",
"metrics" => "ga:users,ga:newUsers,ga:percentNewSessions,ga:sessions,ga:bounces,ga:bounceRate,ga:avgSessionDuration,ga:goalStartsAll,ga:pageviews,ga:pageViewsPerSession",
"start-date" => "730daysAgo",
"end-date" => "today",
"max-results" => 10000
]);
$curl->setHeaders([
"Authorization" => "Bearer " . #$this->aim_account->settings["credentials"]["access_token"]
]);
$data = $curl->sendRequest("json");
return $data;
}
I mean, just the url and params I need to send in the body of the request. But I don't seem to be able to find such information.
Thank you for your time! Any help is welcomed!

Google Analytics server-side tracking

Google Analytics, by just placing its sourcecode on my website, automatically tracks everything I used to need (pageviews, unique visitors).
But now, I need to track events, and the only way to do this is to do it server-side. Each time any users does an specific action i need to track, the server posts data to google to track the information, as explained here:
https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#event
And it does works amazingly perfect, but, since I realiced, I am now receiving a LOT of visits from Spain, doubling the visits from USA. And before I implemented the event tracking, Spain wasn't even part of the top 10 countries.
Today I have realiced that my servers are in Spain, and that may be causing the issue.
How can I track the event, without making it count as a pageview?
$url = 'http://www.google-analytics.com/collect';
$data = array('v' => '1', 'tid' => 'UA-HIDDEN-1', 'cid' => $_SERVER["REMOTE_ADDR"], 'ni' => '1', 't' => 'event', 'ec' => '', 'ea' => 'JUMP', 'el' => '');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
Thank you very much!!
You are sending the IP adress as a client id, which is wrong. For one, the client id is supposed to be an UUID. Secondly, Analytics won't recognize that these events belong to an existing user.
You'd need to grab the existing client id for an existing user on the web page:
ga(function(tracker) {
var clientId = tracker.get('clientId');
});
and then send it back to the server and use it in your request (1). At the moment GA cannot assign correct geo information since the events do not belong to the session of the user who initiates the event (this quite possibly affects some other metrics, too).
(1) You might as well read the GA cookie in PHP, but Google recommends against it since the cookie format might change without notice. The script above will always return a correct client id even if the cookie format changes.
Updated: I have read a bit more documentation and while my answer seems still somewhat relevant it's probably wrong for the actual use case - Geo is determined by IP and the serverside script will still send the servers IP. So quite possibly (haven't done the science yet) this would look like one visitor with two devices instead of a single visitor.
Update 2: Apparently it is now possible to include the users IP adress as parameter, so this answer is possibly no longer relevant.
Here is a techopad presentation about mixing UA client- and serverside, maybe that helps.
An event in and of itself is not a pageview. See: Event Tracking
Is there a specific reason why you need to track events server side and pageviews from the normal ga.js client-side code?
You can easily track events from the client side, if you were unaware of that:
Click Link to Track Event
Assuming that you needed to keep events AND pageviews on the server side:
<?php
//Put SERVER_ADDR into a var
$request_ip = $_SERVER['REMOTE_ADDR'];
// Put any server IPs you need to filter out below in an array
$localhosts = array('127.0.0.1','192.168.15.1','10.1.10.1');
// Use this later
$url = 'http://www.google-analytics.com/collect';
Now, Figure out what to do with the REMOTE_ADDR check if its in our list above. then build an array of type to send GA (events, pageviews)
$actions = array();
// Note that the values are arbitrary and will let you do what you need.
if(in_array($request_ip)){
//Only track event, or track pageview differently, or track two events.
$handle_myServer = true;
$actions = ('event');
} else {
// Track everyone else
$handle_myServer = false;
$actions = ('event','pageview','mySpecialPageview','mySpecialEvent');
}
Finally We have built a list of events we can use in flow control with existing code for pageviews, user timing, events, etc. Be creative!
foreach($actions as $action){
$data = null; $options=null;
if($handle_myServer){
$someFlagForGA = 'RequestFromSpainServer';
}
if($action == 'event'){
$data = array('v' => '1'
, 'tid' => 'UA-HIDDEN-1',
,'cid' => $request_ip
,'ni' => '1'
, 't' => 'event'
, 'ec' => $someFlagForGA,
,'ea' => 'JUMP', 'el' => ''
);
} elseif($action == 'pageview'){
$data = array('v' => '1', 'tid' => 'UA-HIDDEN-1'
, 't' => 'pageview'
, 'dh'=> 'yourGAenabledDomainHere.com'
, 'dp'=> 'ViewedPage.html'
, 'dt'=> 'homepage'.' SERVER VISITED '.$someFlagForGA
);
} else {
// Do whatever else
}
// Would be better to do below with a single function
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
) ,$data);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context) or die('Error!!');
}
?>

Twitter stream latest tweets not working

I am trying to show the latest tweets on a webpage, but I am unsure of how to do it as I am very new to the twitter api, but here is what I have thus far.
function my_streaming_callback($data, $length, $metrics) {
echo $data;
}
require '../tmhOAuth.php';
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'key',
'consumer_secret' => 'secret',
'user_token' => 'token',
'user_secret' => 'secret',
));
$method = 'http://stream.twitter.com/1/statuses//show/:id.json';
//not sure where I am supposed to get the :id from?
$params = array(
//not sure what to put here, I would like to display the last 5 tweets
);
$tmhOAuth->streaming_request('POST', $method, $params, 'my_streaming_callback');
$tmhOAuth->pr($tmhOAuth);
I am using this https://github.com/themattharris/tmhOAuth to authenticate, and then interface with the twitter api, but I am finding it very confusing as all of this is very new to me.
So basically I would just like to try and get the latest tweets, any help would be GREATLY appreciated, as I need to get this done ASAP, thanx in advance! :)
Stream API returns you only the tweets posted after you connected. To get previous tweets you need to use general REST API method: http://dev.twitter.com/doc/get/statuses/show/:id
$tmhOAuth->request('GET', $tmhOAuth->url('1/statuses/show/$id'));
$tmhOAuth->pr(json_decode($tmhOAuth->response['response']));
where $id is the user's id.
If you wish you can use THIS beautiful jQuery plugin. It do the some thing as you require. For more information visit http://tweet.seaofclouds.com/

Categories