Insightly API does not work - php

I am trying to connect to my Insightly account via API given on this link: https://github.com/Insightly/insightly-php
When I test the given code:
<?php
require('insightly.php');
function run_tests($apikey){
$insightly = new Insightly($apikey);
$insightly->test();
}
run_tests($argv[1]);
?>
Nothing actually happens, meaning it gives out a blank page. Of course I have changed the variable $apikey with the key given. I have tried with base64 encoding, single quotes, double quotes, but nothing really works. I have also tried on localhost as well as on my server.
Then I tried the code given on Github:
require("insightly.php");
$i = new Insightly('your-api-key');
$contacts = $i->getContacts();
Again, changing the api key with the one given, once normal and once in base64 encoding. This just gives me a 500 error.
Does anybody have any idea how to even connect to Insightly via API in PHP?

This code is made for executing in cli. If you use it like this is will run in a browser or anything else for that matter.
<?php
require('insightly.php');
function run_tests($apikey){
$insightly = new Insightly($apikey);
$insightly->test();
}
$apikey = "[PLACE API KEY HERE]";
run_tests($apikey);
otherwise try the following:
require("insightly.php");
$i = new Insightly('your-api-key');
$contacts = $i->getContacts();
var_dump($contacts);

Related

Why do I get an "ErrorID: 512 invalid clientID" even though the ID is correct?

I've got a php TeamSpeak Bot for quite a while and for one user I now have this weird phenomenon, that the clientID is invalid.
So I store the clientIDs (TeamSpeakUUID) in a MySQL database.
As example:
I fetch the TeamSpeakUUID from the database and want to poke a client on my TeamSpeak with the TS3 PHP Framework (https://github.com/planetteamspeak/ts3phpframework).
For every other client it works expect for one and I have absolutely no idea why.
snippet for the example:
while($row = mysqli_fetch_assoc($result)) {
$client = $ts3_VirtualServer->clientGetByUid($row['TeamSpeakUUID'], true);
$client->poke($msg);
}
I have two UUIDs here
Working: sP0GjP/pVyyfx07MvN+S1Cvt9mc=
Not working: a/1nYOo3Ej3afLa05ElVtxYDOMU=
I don't know why but if I want to poke the client "hardcoded" it works...
$client = $ts3_VirtualServer->clientGetByUid("a/1nYOo3Ej3afLa05ElVtxYDOMU=", true);
Do you guys have any idea(s)?

Trying to use a JSON API that isn't technically an API

I just started playing D&D, and I'm working on a project for my group to help us play the game a littler easier. We all created Characters on D&D Beyond. They don't have an official API, but apparently, if you type in "your-character-sheet/json" - you can get some JSON output about your character.
I attempted to grab this data in php as I normally would
<?php
$request = "https://www.dndbeyond.com/profile/PixiiBomb/characters/9150025/json";
$url = file_get_contents($request);
$json = json_decode($url, true);
echo $json["character"]["id"];
?>
This should echo out: "9150025" - but I actually see nothing. It's totally blank. So I tried to echo $url, and this is what I see.
Which of course, it not what I should be seeing (because that is formatting from their website, minus the stylesheets)
I went back to the JSON view and manually saved the data as pixii.json This time using the following:
$request = "uploads/dndbeyond_sheets/pixii.json"; // Saved to my harddrive
$url = file_get_contents($request);
$json = json_decode($url, true);
echo $json["character"]["id"];
THIS WORKS if I manually save the file. But that would mean that every time we level up, I would have to manually save all of our JSON data, and run some code to read it and update it.
Is there something else I can try to allow me to use this URL instead of having to manually save the page?
Ideally, I would like to have all of my code written , and then when we level up, I press a button and grab the new data from the site (which I don't need help with, that's not part of the question). Instead of manually visiting each website, saving the data, and then parsing it.

Google API Data Tranfer Insert (Google Drive): Says completed, but nothing actually happens

I found a similar article here, but after a lot of testing, I'm still running into issues (Google API Data Transfer Insert: missing resource.applicationDataTransfer).
Essentially I'm trying to transfer ownership of a Google Drive to another person. I got this working for calendars (basically the same code, but different applicationId), but for the Drive, it says it completed without actually moving anything. I have verified that all of the API permissions are correct, and I've even been able to run this successfully in the Google API Explorer (https://developers.google.com/admin-sdk/data-transfer/v1/reference/transfers/insert?authuser=1).
Is there something really simple that I'm missing here?
$service = new Google_Service_DataTransfer($client); // $client is already defined and working properly
$oldUserID = 'oldAccountIdNumberHere';
$newUserID = 'newAccountIdNumberHere';
$driveTransferParams = new Google_Service_DataTransfer_ApplicationTransferParam();
$driveTransferParams->setKey("PRIVACY_LEVEL");
$driveTransferParams->setValue(['SHARED', 'PRIVATE']);
$driveDataTransfer = new Google_Service_DataTransfer_ApplicationDataTransfer();
$driveDataTransfer->setApplicationTransferParams($driveTransferParams);
$driveDataTransfer->applicationId = 'idStringForGoogleDriveAndDocs';
$driveTransfer = new Google_Service_DataTransfer_DataTransfer();
$driveTransfer->setNewOwnerUserId($newUserID);
$driveTransfer->setOldOwnerUserId($oldUserID);
$driveTransfer->setApplicationDataTransfers([$driveDataTransfer]);
$driveResults = $service->transfers->insert($driveTransfer);
My scopes for the client are: Google_Service_DataTransfer::ADMIN_DATATRANSFER,
Google_Service_DataTransfer::ADMIN_DATATRANSFER_READONLY
Thanks in advance!
Actually, I just figured it out. There were some parameters that needed to be passed within an array, and after doing that, it started working properly. Solution to my problem posted below in case it helps other people.
NOTE 1: see the setApplicationTransferParams line
NOTE 2: see the setApplicationId line
$service = new Google_Service_DataTransfer($client); // $client is already defined and working properly
$oldUserID = 'oldAccountIdNumberHere';
$newUserID = 'newAccountIdNumberHere';
$driveTransferParams = new Google_Service_DataTransfer_ApplicationTransferParam();
$driveTransferParams->setKey("PRIVACY_LEVEL");
$driveTransferParams->setValue(['SHARED', 'PRIVATE']);
$driveDataTransfer = new Google_Service_DataTransfer_ApplicationDataTransfer();
$driveDataTransfer->setApplicationTransferParams([$driveTransferParams]);
$driveDataTransfer->setApplicationId(['idStringForGoogleDriveAndDocs']);
$driveTransfer = new Google_Service_DataTransfer_DataTransfer();
$driveTransfer->setNewOwnerUserId($newUserID);
$driveTransfer->setOldOwnerUserId($oldUserID);
$driveTransfer->setApplicationDataTransfers([$driveDataTransfer]);
$driveResults = $service->transfers->insert($driveTransfer);

API url is being encoded with & instead of just &

I'm trying to connect my app up to an API using this code:
class PostcodePrice{
public function getPrice($postcodes){
$apikey = "MYAPIKEY";
$priceurl = "http://api.zoopla.co.uk/api/v1/area_value_graphs.js?area=".$postcodes."&output_type=outcode&api_key=".$apikey;
$price = file_get_contents($priceurl);
$decoded = json_decode($price);
return $decoded->result;
}
}
Now the problem I'm having is my url is being passed to the api and replacing my & with & so my url is looking like this:
http://api.zoopla.co.uk/api/v1/area_value_graphs.js?area="postcode&output_type=outcode&api_key=MYAPIKEY
The API I am using refuses the url with the encoded & so it obviously doesn't work as I get 403's back as a response.
I've tried things such as string replace, htmlspecialchars etc.
Anyone know of how I can stop this from happening?
U can make "$priceurl" url without concatenation like this.
$priceurl = "http://api.zoopla.co.uk/api/v1/area_value_graphs.js?area=$postcodes&output_type=outcode&api_key=$apikey";
Hope it's work for u.

PHP/JSOn: why is https url json-encoded as null?

I have an online MySQL where a table has a column containing an https URL which is stored as varchar(255). For example, here's a screenshot from phpMyAdmin:
The strange thing which is actually happens, is that when I get the data from MySQL through PHP and I encode them into JSON (so that to be delivered to an iOS app) then the caption is always null. Here's my code:
public function fieldInfoByFishID($fish_id){
$sql = mysqli_query($this->config->dbConn,"SELECT * FROM ".$this->config->table_fields." WHERE id_fish='".$fish_id."'");
$v = mysqli_fetch_array($sql,MYSQLI_ASSOC);
$tmp = array(
'id'=>$v['id'],
'id_fish'=>$v['id_fish'],
'description_info'=>utf8_encode($v['description_info']),
'recognition_info'=>utf8_encode($v['recognition_info']),
'place_info'=>utf8_encode($v['place_info']),
'fishing_method'=>$v['fishing_method'],
'buy_period'=>$v['buy_period'],
'caption'=>$v['caption'],
'life_method'=>utf8_encode($v['life_method']),
'exploitation_status'=>$v['exploitation_status']
);
return $tmp;
}
The code looks correct to me but I don't know why that column is not fetched. Is there a particular attention I have to pay in order to get the url correctly? I thought it was just a simple string.
Here's an example:
Obviously, if I tr to exec the sql query in phpMyAdmin console, it all works fine.
Thank you all.

Categories