Trying to upload a csv from a remote URL to azure storage using the PHP SDK. I seem to keep getting this error. I have tried it without the SDK using curl and i still get the same error.
`PUT resulted in a `403 Server failed to authenticate the request.
Make sure the value of Authorization header is formed correctly including the signature.` response:
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate (truncated...)
in C:\wamp64\www\azurescript\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113
Here is my PHP code which i am using:
<?php
require_once 'vendor/autoload.php';
use MicrosoftAzure\Storage\Common\ServicesBuilder;
use MicrosoftAzure\Storage\Common\ServiceException;
use MicrosoftAzure\Blob\Models\SetBlobPropertiesOptions;
$key = base64_encode("abc");
$connectionString = "DefaultEndpointsProtocol=https;AccountName=username;AccountKey={$key}";
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
// Grab the csv from the remote url
$csv = fopen("http://www.xxxxx.com/wp-cron.phpexport_hash=yyyyyy&export_id=1&action=get_data", "r");
$blobName = "test";
try {
// Upload the blob
$blobRestProxy->createBlockBlob("container", $blobName, $csv);
}
catch(ServiceException $e){
// Errors
$code = $e->getCode();
$errorMessage = $e->getMessage();
}
Cant seem to this. Some guidance would be nice
The error is related to 403 auth failed. Please maker sure:
Your account name and account key is valid and not expired. You can confirm this by trying loging with Azure Storage Explorer, or check on your Azure Portal.
You do not need base64_encode($key) again after receiving your key from Azure Storage. The key received from Azure Storage is already base64_encoded.
The auth issue is related to your key not being properly set up. Not sure why you decided to encode it, but... you need to use the storage access key exactly as it's presented to you.
In fact, the entire connection string is constructed for you already; no need to build it yourself.
Related
I can't log in my app using vtwsclib library function doLogin().
I would like retrieve some data from crm via the web services but I keep getting "login failed" message.
Beside that, I got no errors or warning from php.
My system is a xampp localhost, php -v 7.1.33.
Do I have to make some changes within the library code in addition of the code here below?
$url = 'urlofmyvtecrmaccess';the url to my crm access page.
$client = new Vtiger_WSClient($url);
$login = $client->doLogin('mycrmuser', 'mywebserviceaccesskey');
if (!$login)
echo 'Login Failed';
else
echo 'Login Successful';
Did you provide full url to the webservice file ?
Like http://yourcrm.com/webservice.php
You could find if there is any error in the api call using
$client->lastError() method
You can also debug inside doLogin() method to identifiy the error
Check the api response if it has any information of error
You must have to pass your encrypted password and for encryption, you have to use md5.
$encryptedPassword = md5('useraccesskey');
$login = $client->doLogin('mycrmuser', $encryptedPassword);
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.
This is my first time posting here, so forgive me if I leave out something important. Anyway, I'm trying to connect to Etsy's API using PHP and OAuth. I've been following the guide here: https://www.etsy.com/developers/documentation/getting_started/oauth#section_obtaining_temporary_credentials
I already created an account and app on Etsy, so I have my consumer key and secret. I've copied their code for getting a request token 100% and defined the two variables using my unique key and secret. However, when I try to make the http request, I get an "ERR_EMPTY_RESPONSE". When I click to get more detail it says: "Unable to load the webpage because the server sent no data". Here is a screenshot of the error page: http://imgur.com/dgxAlci
I'm using MAMP to make a localhost on port 8888 in order to test any PHP code that I write (e.g. to get to this php file I enter this url: localhost:8888/Etsy/EtsyOAuth.php).
My code is below. I edited out my key and secret.
define('OAUTH_CONSUMER_KEY', "****");
define('OAUTH_CONSUMER_SECRET', "****");
// instantiate the OAuth object
// OAUTH_CONSUMER_KEY and OAUTH_CONSUMER_SECRET are constants holding your key and secret
// and are always used when instantiating the OAuth object
$oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
// make an API request for your temporary credentials
$req_token = $oauth->getRequestToken("https://openapi.etsy.com/v2/oauth/request_token?scope=email_r%20listings_r", 'oob');
print $req_token['login_url']."\n";
I'm using pHP 5.6.7 and OAuth 1.2.3 says phpinfo().
Any help is much appreciated. Thanks in advance!
Can anyone tell how I can implement a Oauth api for my site.I have downloaded the example from http://code.google.com/p/oauth-php/downloads/list(oauth-php-175.tar.gz)
I have created the database and run the register.php file in example/server and i got a consumer key and secret key.I have replaced the api key and secret key with this in client/twolegged.php.The url mentioned their is replaced with server/www/hello.php
But when i run the file client/twolegged.php am getting the error
ExceptionRequest failed with code 401: Can't verify request, missing oauth_consumer_key or oauth_token-OAuth Verification Failed:
Is it the correct way to do this? Please help me?
Use
$server->verifyIfSigned(false)
instead of
$server->verifyIfSigned()
in hello.php
In my application i want to use the Soundcloud API with my own Soundcloud user. The Soundcloud API authentication process involves a user being redirected to the Soundcloud homepage, login and authorize the application, so that the page can use the API for this user.
I want to automate the whole process, because my own user is the only user which gets authenticated. Is that possible?
Here is my code so far:
$soundcloud = new \Services_Soundcloud(
'**',
'**',
'http://**'
);
$authorizeUrl = $soundcloud->getAuthorizeUrl();
$accessToken = $soundcloud->accessToken();
try {
$me = json_decode($soundcloud->get('me'), true);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
But the line $accessToken = $soundcloud->accessToken(); throws an exception:
The requested URL responded with HTTP code 401.
500 Internal Server Error - Services_Soundcloud_Invalid_Http_Response_Code_Exception
Hi All,
Here I am going to share my experience with Soundcloud API (PHP)
See my Question: Link
Recently I started to work with Sound cloud API (PHP) and I decided to use PHP API by
https://github.com/mptre/php-soundcloud.
But When I was trying to get access token from Sound cloud server by this code:
// Get access token
try {
$accessToken = $soundcloud->accessToken($_GET['code']);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
I had check the $_GET['code'] value. But strange there is nothing in
$_GET['code'] this is blank. The Soundcloud was returning "The
requested URL responded with HTTP code 0" error. That time I was
testing Soundcloud on WAMP Localhost.
Allot of Goggling I found a solution to fix "The requested URL
responded with HTTP code 0" issue. I had download 'cacert.pem' file
and put inside our demo project folder (inside Services/Soundcloud/).
Then after I added some code in 'class Services_Soundcloud'
function protected function _request($url, $curlOptions = array()).
// My code in side function
$curlPath = realpath(getcwd().'\Services\cacert.pem');
$curlSSLSertificate = str_replace("\\", DIRECTORY_SEPARATOR, $curlPath);
curl_setopt($ch, CURLOPT_CAINFO, $curlSSLSertificate);
Saved 'class Services_Soundcloud' file and moved on live server. After
move my project from WAMP to Live server I start to check it again.
When I open my index.php it's ask me to login
I use my Facebook account to login.
after login it was asking to connect with Soundcloud
after connect everything working smooth, I got my info with
$me = json_decode($soundcloud->get('me'));
but a new problem start to occurring which was that my access token
being expire again and again. Then I use session :D
// code for access token
$code = $_GET['code'];
// Get access token
try {
if(!isset($_SESSION['token'])){
$accessToken = $soundcloud->accessToken($code);
$_SESSION['token'] = $accessToken['access_token'];
}else{
$soundcloud->setAccessToken($_SESSION['token']);
}
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
And now everything working awesome. i can get all my details, tracks everything from SC server
Hope it will help you to fight with Soundcloud API Cheers!!!! :)
I'm looking for the same thing, but according to the soundcloud's api (check the Authenticating without the SoundCloud Connect Screen paragraph):
// this example is not supported by the PHP SDK
..and is not supported by the Javascript neither.
I've tryed to auth with python:
# create client object with app and user credentials
client = soundcloud.Client(client_id='YOUR_CLIENT_ID',
client_secret='YOUR_CLIENT_SECRET',
username='YOUR_USERNAME',
password='YOUR_PASSWORD')
..then the uploading python method:
# upload audio file
track = client.post('/tracks', track={
'title': 'This is my sound',
'asset_data': open('file.mp3', 'rb')
})
and it works just fine.
So, for now, you have 2 ways:
Use another language, Python or Ruby (the only 2 sdk that actually support this feature) or use a small python/ruby script as a bridge for this particular need;
Add this funcionaliy to the PHP SDK (i'm trying to do it quick'n'dirty, if i get success, i'll share ;)
There is no magic behind its implementation in Python and Ruby SDK's.
What's happening is that POST request is sent to http://api.soundcloud.com/oauth2/token with the following params:
client_id='YOUR_CLIENT_ID'
client_secret='YOUR_CLIENT_SECRET'
username='YOUR_USERNAME'
password='YOUR_PASSWORD'
And Content-Type: application/x-www-form-urlencoded
The response body contains access_token, that can be used for the further authorization of your requests. Thus, your GET request to /me endpoint will look like: /me?oauth_token=YOUR_ACCESS_TOKEN&client_id=YOUR_CLIENT_ID. (I believe, client_id is redundant here but all their apps keep adding it).
Here is the Postman Doc I created for demonstration: https://documenter.getpostman.com/view/3651572/soundcloud/7TT5oD9