How can I get number of followers with Spotify API? - php

I'm trying to get an artist's number of followers.
If I use the metadata api call
http://ws.spotify.com/lookup/1/?uri=spotify:artist:4YrKBkKSVeqDamzBPWVnSJ
I just get the name of the artist.

I'm assuming you want a PHP solution.
Using the spotify-web-api-php library (shameless self promotion) it's really easy. Take a look at this example:
<?php
require_once 'src/Request.php';
require_once 'src/SpotifyWebAPI.php';
$api = new SpotifyWebAPI\SpotifyWebAPI();
$artist = $api->getArtist('0OdUWJ0sBjDrqHygGUXeCF');
echo '<b>Number of followers:</b> ' . $artist->followers->total;
As mentioned earlier, also take a look at the official Spotify docs.

Related

how to fetch a page's likes from fb by php

i want to make a social media audit tool and i want to get likes of a person's Fb page. Basically what i want is i want that person to enter his FB pages URL and then i want to fetch the likes of his page and echo it in my PHP page. Is there any way I can do that without using graph API or any API. I just want a simple piece of code.
I have searched many questions regarding my project on web and on StackOverflow as well but coudn't find what i wanted, at last, I am asking this question. Is there anyone who can help me regarding this?
Thanx in advance.
<?php
$file = "https://www.facebook.com/IntellectualIndies/?epa=SEARCH_BOX";
$data = file_get_contents($file);
preg_match_all ('~<div class=\'_4bl9\'>\s*(<div.*?</div>\s*)?(.*?)</div>~is', $data, $matches);
$content = $matches[1];
$total = count($content);
for($i=0; $i<$total; $i++){
echo $content[$i]."<br />";
}
?>
i tried this code.
Is there any way I can do that without using graph API or any API
No, scraping is not allowed on Facebook.
There is only one way to do this:
Apply for Page Public Content Access
Use the Graph API with the following endpoint/field: /page-id?fields=fan_count
API Reference with example code: https://developers.facebook.com/docs/graph-api/reference/page/

Get keyword ideas by page URL in Google AdWords API

I'm trying to get keyword ideas from AdWords API by page URL, but so far I'm only able to get keywords list by another keyword.
What I want to do is possible via web interface, but as for API, docs say that the only available value for ideaType property is KEYWORD.
Are there any alternatives for ideaType, maybe via creating a new campaign, or something else?
I'm using PHP.
I'm new to Google AdWords. Help appreciated!
In fact, I misunderstood the goal of ideaType property. This property is not the input search parameters type.
For getting keyword ideas by URL you can use RelatedToUrlSearchParameter class.
In my case code looks like following (the most relevant part):
$selector = new TargetingIdeaSelector();
$selector->requestType = 'IDEAS';
$selector->ideaType = 'KEYWORD';
$selector->requestedAttributeTypes = array('KEYWORD_TEXT', 'SEARCH_VOLUME', 'CATEGORY_PRODUCTS_AND_SERVICES');
$relatedToUrlSearchParameter = new RelatedToUrlSearchParameter();
$url = $_GET['url'];
$relatedToUrlSearchParameter->urls = array($url);
$selector->searchParameters[] = $relatedToUrlSearchParameter;

PHP - Twilio Recording Duration Value Issue

So I'm creating an application that allows users to record a message through Twilio and I'm attempting to store the RecordingSID, the date it was created, and the duration of the recording in a MySQLi database right after the recording has been made. I've managed to get the RecordingSID by taking the last 34 digits off the RecordingURL using the substr() function and am simply getting whatever today's date is for the date created field in my database table. However, seemingly regardless of how long the actual recording is, I'm continually getting a value of 8 when attempting to get the recording duration. Here's what I've got right now (with database inserts omitted since they work):
<?php
$recordingURL = $_REQUEST['RecordingUrl'];
$recordingSID = substr($recordingURL, -34);
date_default_timezone_set('EST');
$dateCreated = date("Y-m-d");
$duration = $_REQUEST['RecordingDuration'];
?>
Any help with this matter would be fantastic! Thanks!
Edit: I've also tried the following solution in place of the last line in my previous code snippet:
<?php
$recordings = $client->account->recordings->getIterator(0, 50, array('Sid' => $recordingSID,));
foreach ($recordings as $recording)
{
$duration = $recording->duration;
}
?>
Based on that code sample you've pasted in, you could be doing a couple of things incorrectly. Correct me if I'm wrong, but I believe you are trying to request a Recording resource back from the Twilio API after you've submitted one with the Twilio js and their TwiML?
If so, twilio actually has a nice little demo of exactly your use case.
You shouldn't see anything in the $_REQUEST['RecordingDuration'], I'm not sure why you are even getting a value of 8 returned. Basically what you want to do is find the users recordings by using the Twilio REST API.
here is an example snippet:
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACda6f132a3c49700934481addd5ce1659";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
// Loop over the list of recordings and echo a property for each one
foreach ($client->account->recordings as $recording) {
echo $recording->duration;
}
The response from the API call will return a Recording resource.
Here is some more examples from their docs

Getting just number of facebook likes

I'm curious to use the facebook graph API as I don't like the simple like button with number of likes next to it. However I'm finding their documentation a bit confusing. I want to do this via PHP so I'm assuming I need the PHP SDK, is that right?
I'm looking at this page Graph API: Page however I don't understand how I would call the likes.
I'm not asking for someone to code this for me, just a little help in the right direction to understand how it works :)
Try this:
$json = #file_get_contents("http://graph.facebook.com/yourpage");
$json1 = json_decode($json,true);
$likes = $json1['likes'];
echo $likes;
This is pretty straightforward. Using the ID or the username of the page, access that
node via the Graph API:
PAGE_ID?fields=likes
In PHP would be something like:
$token_string = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id='.$appID.'&client_secret='.$app_secret.'&grant_type=client_credentials');
$likes_response = file_get_contents('https://graph.facebook.com/PAGE_ID?fields=likes&'.$token_string);
$likes_obj = json_decode($likes_response);
$likes = $likes_obj->likes;
echo 'Likes count for page: ' . $likes;

can I use a number of "facebook likes" in php?

I am using facebook like in my site, and my php script need to know how many people like every page. For example I want to use in php echo $likes; where $likes is a number of likes. Is it possible to do?
Using the new Graph API this is fairly straight forward.
Just do: https://graph.facebook.com/uniqueid/members
Using the new SDK library (http://github.com/facebook/php-sdk/) do the following:
$facebook = new Facebook($appId,$secret);
$facebook->api('uniqueid/members');
This should return a JSON array which you can iterate.

Categories