Infusionsoft Getting Tags - php

I am new to the Infusion API and I have a couple of questions that I am unable to find a specific answer to.
I have used the PHP SDK and installed via composer
1) Within the new API is there away that I can view all tags that have been created?
2) I have created and got my client clientId and clientSecret via but I am unsure how I connect it to the app name that I want to fetch the tags for.
I have given it an attempt by looking at code examples I have seen via Google however I am getting the following error - Call to undefined method Infusionsoft\Infusionsoft::dsQuery()
Code:
<?php
//Connect to the Infusionsoft API
require_once 'vendor/autoload.php';
$infusionsoft = new \Infusionsoft\Infusionsoft(array(
'clientId' => 'key',
'clientSecret' => 'key',
));
// Fetch the required tags for this place
$getFields = array('Id','GroupDescription', 'GroupName');
$query = array('GroupName' => '%');
$tags = $infusionsoft->dsQuery("ContactGroup",1000,0,$query,$getFields);
var_dump($tags);
?>

First of all, there's no new API. Improvements are added to Infusionsoft API all the time, but it's still the same updated API. If you mean new Infusionsoft PHP SDK, then example request to get the tags looks this way:
$infusionsoft->data()->query('ContactGroup', $limit, $page, $queryData, $selectedFields, $orderBy, $ascending);
query() method is implemented in Infusionsoft/Api/DataService.php file
You connect to a specific Infusionsoft account during oAuth authorization flow. This basic flow is shown, for example, in PHP SDK examples
The error you see means exactly what it says - there's no such method dsQuery() in the updated SDK. The link to the SDK code where you can see all available methods was provided in the first point.

Related

How to return all Campaign information for a specific user by calling the Facebook market API using the Facebook-business-php-sdk

I'm trying to get all campaign IDs using the supplied code from the API graph explore tool but the code supplied by the Graph API tool returns and error.
The Facebook initialization code is below
$api = new \Facebook\Facebook([
'app_id' => '00000',
'app_secret' => '0000',
]);
When I run the following code:
$response = $api->get(
'/act_0000000/campaigns',
'{Token}'
);
The following error is returned:
You are calling a deprecated version of the Ads API. Please update to the latest version: v3.2.
Or when I update the code to match what is specified as the latest version:
$response = $api->get(
'v3.3/act_0000000/campaigns',
'{Token}'
);
Then the following error is returned:
Unknown path components: /act_00000000/campaigns
I've tried using the Raw SDK but the documentation seems to be either depreciated or not working all together. Any help or advice is greatly appreciated, I could use the cURL method but id rather use the raw SDK.
The way i was able to resolve the issue was by running the following code, the docs seems to only be updated on the Facebook-business-php-sdk GitHub link
you could either manually pass the string to the AdAccount() like i id or dynamically though a for-each.
Api::init($app_id, $app_secret, $access_token);
Api::instance();
$data = new AdAccount('act_00000');
$results = $data->getCampaigns(['id', 'name']);

Spotify Web API - Client Credentials - Accessing a users playlists

I'm trying to access users playlist tracks by using the client credentials flow.
Spotify getting playlist documentation: https://developer.spotify.com/web-api/get-playlists-tracks/
Spotify getting client credentials documentation: https://developer.spotify.com/web-api/authorization-guide/
First question, is it possible to get a users playlist tracks using client credentials flow? I'm using this flow since I'm unable to pop up a login box for the user to login.
Secondly, I've tried using https://github.com/jwilsson/spotify-web-api-php client credentials flow (Docs: http://jwilsson.github.io/spotify-web-api-php/authorization.html) by practically copying the code at the bottom of that page:
<?php
include('vendor/autoload.php');
$session = new SpotifyWebAPI\Session('Tobys client id', 'Tobys secret', 'http://localhost/callback');
// Request a access token with optional scopes
$scopes = array(
'playlist-read-private',
'user-read-private'
);
$session->requestCredentialsToken($scopes);
$accessToken = $session->getAccessToken(); // We're good to go!
// Set the code on the API wrapper
$api->setAccessToken($accessToken);
$playlists = $api->getUserPlaylists('USER_ID', array(
'limit' => 5
));
foreach ($playlists->items as $playlist) {
echo '' . $playlist->name . ' <br>';
}
This gives me Notice: Undefined variable: api in /var/www/html/dev/testing.php on line 16
I've also tried creating the API variable using $api = new SpotifyWebAPI\SpotifyWebAPI(); but this says I need user information/ tokens.
Thanks.
First question, is it possible to get a users playlist tracks using
client credentials flow?
Yes, retrieving tracks for a playlist doesn't require user authentication as part of the access token.
I've also tried creating the API variable using $api = new
SpotifyWebAPI\SpotifyWebAPI(); but this says I need user information/
tokens.
Looking at the code (Session class, SpotifyWebapi class), it does look like you should set this up by doing
$api = new SpotifyWebAPI\SpotifyWebAPI();
$session = new SpotifyWebAPI\Session($clientId, $clientSecret, $redirectUri);
$api->setAccessToken($session->getAccessToken());
When that's set up you should be good to use the getUserPlaylists method like you're doing in your example code.

Using Google's API through laravel/hybridauth

I want to create an app that uses Google+ APIs through hybridauth.
I'm using atticmedia/anvard version of hybridauth, that is already configured with Google's clientID and secretKey that have been generated through Google Developer Console (I have inserted these info inside the hybridauth.php file inside the config folder of laravel). I have setted the scope too (as Google suggest).
"scope" => "https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email",
I do the following in a laravel route:
if (!$hybridauth->isConnectedWith('Google')) {
$adapter = $hybridauth->authenticate('Google');
}
else {
$adapter = $hybridauth->getAdapter('Google');
}
$profile = $adapter->getUserProfile();
Till now, everything goes well. The profile is correctely printed using the var_dump() function. So I can assume I am logged in. Now I want to make a call to Google APIs (for example this). In the same laravel route, after printing the user's profile, i do the following:
$answer= $adapter->api()->api('/people', 'get', array(
'query' => 'Google'
));
As shown in this page, I can use the api() method to do the call. But the only result I can print is "NULL". I suspect that somehow the request is not correct, but I tryed almost anything, and I have not found yet a "real" example of Google API in conjuction with laravel/hybridauth.
When calling $adapter->api in hybridauth to access Google APIs, you must use the full HTTP URL request.
$answer= $adapter->api()->api('https://www.googleapis.com/plus/v1/people/me');
For other services, such as Facebook, you don't need to
$answer= $adapter->api()->api('/me');
I'm using Laravel 4.2.11 and hybridauth dev-master
Reference: http://hybridauth.sourceforge.net/userguide/tuts/advanced-access-google-api.html

Rendering SoundCloud widget for a private track using PHP API

I am trying to render a SoundCloud HTML5 widget using the PHP API, but every time I run the command I think should return the HTML for the widget, I simply get an Exception:
The requested URL responded with HTTP code 302
I realise this is a redirect. What I don't know is why that's all I ever get, or what to do about it to actually get the widget HTML.
The documentation on the API says that to embed the widget using PHP you should do this:
<?php
require_once 'Services/Soundcloud.php';
// create a client object with your app credentials
$client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
// get a tracks oembed data
$track_url = 'http://soundcloud.com/forss/flickermood';
$embed_info = $client->get('/oembed', array('url' => $track_url));
// render the html for the player widget
print $embed_info['html'];
I'm running this:
// NB: Fully authorised SoundCloud API instance all working prior to this line
// $this->api refers to an authorised instance of Services_Soundcloud
try {
$widget = array_pop(
json_decode( $this->api->get('oembed', array('url' => $track_url)) )
);
print_r($widget);
} catch (Exception $e)
{
print_r($e->getMessage());
}
where "track_url" is actually the URL I get back when asking SoundCloud for a track object earlier in the app using the same API.
I'm not actually sure this URL is correct in the first place, because the track object I get back gives the 'uri' in the form:
[uri] => https://api.soundcloud.com/tracks/62556508
The documentation examples all have a straight http://soundcloud.com/username/track-permalink URL - but even using a known path to a public track the attempt to run the API oembed method fails... I still get a 302 Exception.
Finally, there are mentions of setting "allow_redirects" to false in the 'get' command, but this has no effect when I add to the parameters used to build the query to the API. I also tried adding additional cURL options, but that too had no effect.
I have definitely enabled API access to the track within SoundCloud.
Kind of banging my head off the wall on this. If anyone has any pointers I'd be very grateful to hear them. Just for clarity's sake, I am able to access all the user data, comments etc. via the API instance I have created, so it appears to be working fine.
Thanks for pointing this out. There was a bug in the documentation that lead you astray. Sorry about that. I've updated the docs to fix the bug. Here's the updated code sample:
<?php
require_once 'Services/Soundcloud.php';
// create a client object with your app credentials
$client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
$client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => 1));
// get a tracks oembed data
$track_url = 'http://soundcloud.com/forss/flickermood';
$embed_info = json_decode($client->get('oembed', array('url' => $track_url)));
// render the html for the player widget
print $embed_info->html;
Note the differences:
You need to set CURLOPT_FOLLOWLOCATION to 1 as mentioned in the comments above.
You need to wrap the return from $client->get in json_decode
The result is an stdClass object, not an Array and so the html property has to be accessed using the -> operator.
Hope that helps. Feel free to comment in case you're still having problems and I'll amend my answer.

Twitter API post statuses/filter with Twitter OAuth Class

I keep getting error code 34 (Sorry, this page does not exist) when attempting to make a post request to the statuses/filter method with the abraham twitteroauth class (https://github.com/abraham/twitteroauth). Following authentication (that's working fine) my request is simple:
$filter = $twitteroauth->post('statuses/filter',array('track' => 'seo'));
I have other calls working but even when I isolate this on a separate instance of the site, I'm only receiving the "Sorry, that page does not exist" error.
Any help would be appreciated.
TwitterOAuth does not currently support the Streaming APIs. You can try the method that #JohnC suggests but I don't know if it will actually work.
Phirehose is the PHP library I recommend for use with the Streaming APIs.
The statuses/filter call uses a different URL to many of the other API calls - using stream.twitter.com instead of api.twitter.com. The library you are using appears to be hardcoded to only use api.twitter.com, so this could be the source of your problem. You can either change the URL for that call:
$twitteroauth->host = "https://stream.twitter.com/1/";
$filter = $twitteroauth->post('statuses/filter',array('track' => 'seo'));
Or if you use the full URL it will override the default (probably the best way if you make multiple calls to the $twitteroauth class):
$filter = $twitteroauth->post('https://stream.twitter.com/1/statuses/filter.json',array('track' => 'seo'));

Categories