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
Related
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.
So, I've downloaded Azure SDK for php and started the emulator. Everything ok.
Then I copy&pasted code from Microsoft, so I can create a new test container.
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;
// Create blob REST proxy.
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService('UseDevelopmentStorage=true');
// OPTIONAL: Set public access policy and metadata.
// Create container options object.
$createContainerOptions = new CreateContainerOptions();
// Set public access policy. Possible values are
// PublicAccessType::CONTAINER_AND_BLOBS and PublicAccessType::BLOBS_ONLY.
// CONTAINER_AND_BLOBS:
// Specifies full public read access for container and blob data.
// proxys can enumerate blobs within the container via anonymous
// request, but cannot enumerate containers within the storage account.
//
// BLOBS_ONLY:
// Specifies public read access for blobs. Blob data within this
// container can be read via anonymous request, but container data is not
// available. proxys cannot enumerate blobs within the container via
// anonymous request.
// If this value is not specified in the request, container data is
// private to the account owner.
$createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
// Set container metadata.
$createContainerOptions->addMetaData("key1", "value1");
$createContainerOptions->addMetaData("key2", "value2");
try {
// Create container.
$blobRestProxy->createContainer("mycontainer", $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 $code . ": " . $error_message . "<br />";
}
When I run this code, I get a nice error message.
404: Fail:
Code: 404
Value: The specified resource does not exist.
What's wrong with this? I'm running out of ideas. Firstly I had a slightly different code that didn't work either, so now I try to use this sample directly from MS with no luck.
CLI shows that the emulator is running and also that endpoints are correct.
I used Fiddler to capture the http request generated by the SDK, the url path was /testcontainer?restype=container. And according the Rest API guide https://msdn.microsoft.com/en-us/library/azure/dd179468.aspx, the url path should be /devstoreaccount1/mycontainer?restype=container.
Currently, there is a workaround to develop with Azure Storage on local emulator. We can add the local account name devstoreaccount1 every time when we use the container name, e.g.
$blobRestProxy->createContainer("devstoreaccount1/testcontainer");
$blobRestProxy->createBlockBlob("devstoreaccount1/testcontainer", "testblob", "test string");
$blobRestProxy->listBlobs("devstoreaccount1/testcontainer");
Any further concern, please feel free to let me know.
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?
I want to send push notifications to iPhone devices by writing PHP code for it.
gomoob:php-pushwoosh is a PHP Library that easily work with the pushwoosh REST Web Services.
This is the URL for gomoob:php-pushwoosh
As per the instructions I've installed gomoob:php-pushwoosh on my local machine using Composer at location '/var/www/gomoob-php-pushwoosh'
I wrote following code in a file titled sample_1.php which is present at location '/var/www/gomoob-php-pushwoosh/sample_1.php'
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
require __DIR__.'/vendor/autoload.php';
// Create a Pushwoosh client
$pushwoosh = Pushwoosh::create()
->setApplication('XXXX-XXX')
->setAuth('xxxxxxxx');
// Create a request for the '/createMessage' Web Service
$request = CreateMessageRequest::create()
->addNotification(Notification::create()->setContent('Hello Jean !'));
// Call the REST Web Service
$response = $pushwoosh->createMessage($request);
// Check if its ok
if($response->isOk()) {
print 'Great, my message has been sent !';
} else {
print 'Oups, the sent failed :-(';
print 'Status code : ' . $response->getStatusCode();
print 'Status message : ' . $response->getStatusMessage();
}
?>
But I'm getting following error for it :
Fatal error: Class 'Pushwoosh' not found in /var/www/gomoob-php-pushwoosh/sample_1.php on line 9
At the Link they have not mentioned that any file needs to be included into the code. They have only written sample code program. I've used that program as it is but getting error for it.
So can someone please help me in running this program?
The class you want resides in a namespace, so you need to instruct PHP to "import" it (and other classes) from there; add this to the beginning of your script:
use Gomoob\Pushwoosh\Client\Pushwoosh;
use Gomoob\Pushwoosh\Model\Request\CreateMessageRequest;
use Gomoob\Pushwoosh\Model\Notification\Notification;
require __DIR__.'/vendor/autoload.php';
I have the following PHP code, which up to a week or so ago was working to send Twitter direct messages to a particular user. I now get "HTTP_OAuth_Exception: Unable to connect to tcp://api.twitter.com:80. Error #0: php_network_getaddresses: getaddrinfo failed: Name of service not known in /usr/share/pear/HTTP/OAuth/Consumer.php on line 257"
I've searched around and can't find that anything has changed with Twitter since it was working and the server configuration also hasn't changed. I tried using SSL in case Twitter suddenly required connection via SSL, but that gave basically the same error (except it said ssl and port 443).
I'm at a loss to see what's wrong and don't believe anything changed on my side. My code is based on the example in the Services_Twitter documentation (http://pear.php.net/package/Services_Twitter/docs/latest/Services_Twitter/Services_Twitter.html#var$oauth)
Any help would be greatly appreciated.
require_once 'Services/Twitter.php';
require_once 'HTTP/OAuth/Consumer.php';
$twitterto = 'xxxxxxxxxxxx';
$message='This is a test message';
$cons_key='xxxxxxxxxxxx';
$cons_sec='xxxxxxxxxxxx';
$auth_tok='xxxxxxxxxxxx';
$tok_sec='xxxxxxxxxxxx';
try {
$twitter = new Services_Twitter();
$oauth = new HTTP_OAuth_Consumer($cons_key,
$cons_sec,
$auth_tok,
$tok_sec);
$twitter->setOAuth($oauth);
// The error is raised on the following line.
$twitter->direct_messages->new($twitterto, $message);
$twitter->account->end_session();
} catch (Services_Twitter_Exception $e) {
echo $e->getMessage();
}