404 error using Valence GET classlist - php

I'm trying to retrieve a classlist using the PHP Valence API, and I keep getting the 404 error:
string(39) "Unknown error occured (HTTP status 404)"
Not sure what is causing this error as I've gotten good results when using the same call in the API test tool.
/d2l/api/le/1.0/123456/classlist/
Here is the code:
<?php
require_once "config.php";
require_once $config['libpath'] . "/D2LAppContextFactory.php";
require_once $config['libpath'] . "/DoValenceRequest.php";
$authContextFactory = new D2LAppContextFactory();
$authContext = $authContextFactory->createSecurityContext($config['appId'],$config['appKey']);
$hostSpec = new D2LHostSpec($config['host'],$config['port'],$config['scheme']);
$opContext = $authContext->createElevatedContextFromHostSpec($hostSpec,$config['elevated_username'],$config['ele$
$response = doValenceRequest($opContext,'GET','/d2l/api/le/1.0/123456/classlist');
var_dump($response);exit;
?>
123456 = the OrgUnitId
Why am I getting a 404 error?
Any help would be much appreciated!
-- Valence Newbie

First of all, I would recommend that you change the API version that you are using. Version 1.0 is now obsolete. Here is a link explaining Valence versioning:
http://docs.valence.desire2learn.com/about.html#current-release-changes
My second thought is that is the OrgUnitId actually 123456? Or is that the OrgUnitCode?

Related

Google PlayIntegrity API - validate token via PHP

I am no professional Android developer and I'm having problems to get the Google PlayIntegrity token from my app to decode via PHP through my back-end server and couldn't find much help online.
I included the Google PHP API onto my server, integrated the API into my app and activated&linked it on the Play Console. But it seems I am doing something wrong, I am getting the following PHP error messages:
Warning: Attempt to read property "appLicensingVerdict" on null
My code:
<?php
namespace foo;
use Google\Client;
use Google\Service\PlayIntegrity;
use Google\Service\PlayIntegrity\DecodeIntegrityTokenRequest;
require_once __DIR__ . '/google/vendor/autoload.php';
// Google Integrity token, as obtained from Google through my app:
$token = $_POST['IntegrityToken'];
$client = new Client();
$client->setAuthConfig('google/credentials.json');
$client->addScope(PlayIntegrity::PLAYINTEGRITY);
$service = new PlayIntegrity($client);
$tokenRequest = new DecodeIntegrityTokenRequest();
$tokenRequest->setIntegrityToken($token);
$result = $service->v1->decodeIntegrityToken('com.myapp.game', $tokenRequest);
// Read and handle the JSON response:
$appLicensingVerdict = $result->accountDetails->appLicensingVerdict;
// ... more fields are available in the JSON... see Google documentation
// Check/verify the obtained response values.....
?>
Any help would be much appreciated! Many thanks!
Also thanks to hakre's help, I was able to solve the problems I was facing. The code works fine with tokenPayLoadExternal included:
$appLicensingVerdict = $result->tokenPayloadExternal # <-- this
->accountDetails
->appLicensingVerdict
;

How do I code in PHP this instruction provided by a vendor "DELETE /<domain>/unsubscribes/<address>"

I am working with Mailgiun. Their documentation shows a php example for obtaining a list of email addresses (see below), which I have working in my own code.
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = 'YOUR_DOMAIN_NAME';
$recipient = 'bob#example.com';
$tag = '*';
# Issue the call to the client.
$result = $mgClient->suppressions()->unsubscribes()->create($domain, $recipient, $tag);
I want to remove an entry in their list, and their code example for doing so only shows the following line of code:
DELETE /<domain>/unsubscribes/<address>
How do I code the line above using PHP?
Note:
I have tried the following block of code,
$result = $mailgun_client->suppressions()->bounces()->delete('mg.quikkast.com', 'emailaddress#gmail.com');
but get back a the following error:
Mailgun\Exception\HttpClientException: The endpoint you have tried to access does not exist. Check if the domain matches the domain you have configure on Mailgun.
Thus far Mailgun has not responded with a solution to my support ticket. So any help would be greatly appreciated.
Upgraded to latest version of MG library. Posted a new question to specifically get MG to correct error their code is reporting.

How to properly require stripe library to avoid Error 500 on stripe Webhook

I'm trying to use stripe Webhooks but struggling a little bit.
I have an endpoint file ipn.php at the root of my website.
I also have installed stripe source code.
Though stripe interface, I send a test Webhook to this endpoint.
This code works well :
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$input = #file_get_contents('php://input');
$event = json_decode($input);
http_response_code(200);
if($event->type == "charge.succeeded") {
echo $event->data->object->id;
}
?>
When I test
but as soon as I add those two lines :
require_once('stripe/lib/Stripe.php');
Stripe::setApiKey("whsec_myAPIKeyHere");
I've got this response :
Fatal error: Uncaught Error: Class 'Stripe' not found in /home/ftpHostName/www/myWebsiteWithout.com/ipn.php:11
Stack trace:
0 {main}
thrown in /home/ftpHostName/www/myWebsiteWithout.com/ipn.php:11 on line 11
I havent done any php before, and I think the problem comes from the require_once('stripe/lib/Stripe.php');
Stripe documentation says to use Composer (which I don't know how to use) or download the source code (that's what I did). https://stripe.com/docs/libraries#php
Also, in the error, I don't understand the url I get : why the FTP hostname appears here ?
The reason this is happening is because its not finding the class Stripe.
This is most likely happening because the path of the file containing the class - stripe/lib/Stripe.php is not correct.
Without knowing where the stripe directory is, its hard to say exactly what path you need to put, but if you have the stripe directory in the same path as the ipn.php like:
ipn.php
stripe/
stripe/lib/
stripe/lib/Stripe.php
Then you can just do:
require_once (__DIR__ . '/stripe/lib/Stripe.php');
So your file will look something like this:
<?php
require_once (__DIR__ . '/stripe/lib/Stripe.php');
ini_set('display_errors',1);
error_reporting(E_ALL);
Stripe::setApiKey("whsec_myAPIKeyHere");
$input = #file_get_contents('php://input');
$event = json_decode($input);
http_response_code(200);
if($event->type == "charge.succeeded") {
echo $event->data->object->id;
}
?>
Where __DIR__ returns the current directory of the working file.
You should include the init.php that comes with Stripe's PHP SDK, rather than trying to directly load Stripe.php, e.g. require_once (__DIR__ . '/stripe-php/init.php')
Stripe describes this here.

Error when creating container in Azure

I have installed today Azure Client Libraries using direction on this page https://learn.microsoft.com/en-us/azure/storage/blobs/storage-php-how-to-use-blobs#create-a-php-application
but i am getting below error.
400: Fail:
Code: 400
Value: The value for one of the HTTP headers is not in the correct format.
details (if any): InvalidHeaderValueThe value for one of the HTTP headers is not in the correct format. RequestId:f0046f48-001e-0046-22ab-2823fb000000 Time:2017-09-08T14:06:55.1682373Zx-ms-version2012-02-12.
My Code is as below:
require_once 'vendor/autoload.php';
use WindowsAzure\Common\ServicesBuilder;
use MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions;
use MicrosoftAzure\Storage\Blob\Models\PublicAccessType;
use MicrosoftAzure\Storage\Common\ServiceException;
$connectionString = "DefaultEndpointsProtocol=http;AccountName=MyAccountName;AccountKey=4cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==";
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
//create container
$createContainerOptions = new CreateContainerOptions();
// private to the account owner.
$createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
// Set container metadata.
$createContainerOptions->addMetaData("category", "my first category data");
try {
// Create container.
$blobRestProxy->createContainer("test", $createContainerOptions);
}
catch(ServiceException $e){
// Handle exception based on error codes and messages.
// Error codes and messages are here:
// http://msdn.microsoft.com/library/azure/dd179439.aspx
$code = $e->getCode();
$error_message = $e->getMessage();
echo "Erro in create container <br><br>";
echo $code.": ".$error_message."<br />";
//print_r($e);
}
in above code i got "Class not found" error so updated code as below:
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Blob\Models\CreateContainerOptions;
use WindowsAzure\Blob\Models\PublicAccessType;
use WindowsAzure\Common\ServiceException;
after above change in code, "class not found" error solved and also i checked that connection string is working well but getting error, which described in start of my question.
Thanks :)
Your code looks fine. I can reproduce the error with version v.0.4.2 of Azure SDK for PHP. I got problem solved by upgrading the SDK to the latest version (v0.5.5)
{
"require": {
"microsoft/windowsazure": "^0.5.5"
}
}
There is Azure SDK Version problem so you can download SDK v0.5.5 from my this blog and also can work on your PHP 5.4
http://mytechdevelopment.blogspot.com/2018/01/azure-sdk-055-for-php-54-or-igher.html

Receive error when running basic nuSOAP tutorial

I am trying to create a website that retrieves data from a Web Service using the site API.
The 'nuSOAP' PHP library seems to be a perfect way to go about this and so I have been trying to run through a basic tutorial by Scott Nichol called 'Introduction to NuSOAP'.
Here is the code for server.php:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the server instance
$server = new soap_server;
// Register the method to expose
$server->register('hello');
// Define the method as a PHP function
function hello($name) {
return 'Hello, ' . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
...and here is the code for the client.php:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the client instance
$client = new soapclient('http://localhost/beehive/server.php');
// Call the SOAP method
$result = $client->call('hello', array('name' => 'John'));
// Display the result
print_r($result);
?>
I have 'XAMMP' installed and so when I call up client.php via the browser it should bring up a basic page that says 'Hello, John' but instead I get the following error message:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from '.../server.php' : Start tag expected, '<' not found in C:\xampp\htdocs\beehive\client.php:7 Stack trace: #0 C:\xampp\htdocs\beehive\client.php(7): SoapClient->SoapClient('http://...') #1 >{main} thrown in C:\xampp\htdocs\beehive\client.php on line 7
I figured I should be loading the client page rather than the server, but if I load server.php then I get the error message 'This service does not provide a Web description'.
I have followed the tutorial exactly and can't figure out why it's throwing this error; can anyone please help?
Thank you!
The error you receive makes perfect sense with your error description. The server isn't responding with the right format and therefor your client breaks.
The same error is discussed here:
nusoap simple server
You need to point the client constructor to your wsdl file...
$client = new soapclient('http://localhost/beehive/server.php');

Categories