How to use Bing Translation API? - api

I am trying to use the Bing Translation API, but I am confused.
There seems to be much possibilities (old and new ones) but I don't understand what I have to do.
Can someone please help me?
I want to send a HTTP Request like http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=<AppId>&to=de&text=World and get the translation. Where to get the AppId?
What I have done so far:
Signed in for the free API useage (https://datamarket.azure.com/dataset/bing/microsofttranslator)
Created an App: https://datamarket.azure.com/developer/applications
Now I have the Client_ID and Client_Secret and also I have a account key (visible here https://datamarket.azure.com/account)
What to do now?
Thanks a lot or any help!

AppID is deprecated. How you need perform following steps:
Register you clientID, clientSecter in https://datamarket.azure.com
Then you code must getting access token for login BingTranslator API
Read more details instrustions on http://msdn.microsoft.com/en-us/library/dd576287.aspx
NB Microsoft Translator has been replaced by Bing Translate, which does not appear to have a readily-available API.

Follow the links on http://api.microsofttranslator.com. The API takes an access token in the appid parameter. See the section "Obtaining an access token" in the documentation to learn how to get that token.

Feel free to use this instructions (if you're using php):
Define your keys
$apis['azure']['id'] = 123456789
$apis['azure']['key'] = 'abcde123456';
Classes and functions
class AccessTokenAuthentication {
function getTokens($grantType, $scopeUrl, $clientID, $clientSecret, $authUrl){
try {
$ch = curl_init();
$paramArr = array (
'grant_type' => $grantType,
'scope' => $scopeUrl,
'client_id' => $clientID,
'client_secret' => $clientSecret
);
$paramArr = http_build_query($paramArr);
curl_setopt($ch, CURLOPT_URL, $authUrl);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $paramArr);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$strResponse = curl_exec($ch);
$curlErrno = curl_errno($ch);
if($curlErrno){
$curlError = curl_error($ch);
throw new Exception($curlError);
}
curl_close($ch);
$objResponse = json_decode($strResponse);
if($objResponse->error){
throw new Exception($objResponse->error_description);
}
return $objResponse->access_token;
} catch (Exception $e) {
echo "Exception-".$e->getMessage();
}
}
}
class HTTPTranslator {
function curlRequest($url, $authHeader, $postData=''){
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array($authHeader,"Content-Type: text/xml"));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, False);
if($postData) {
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
}
$curlResponse = curl_exec($ch);
$curlErrno = curl_errno($ch);
if ($curlErrno) {
$curlError = curl_error($ch);
throw new Exception($curlError);
}
curl_close($ch);
return $curlResponse;
}
function xmlLanguageCodes($languageCodes) {
$requestXml = '<ArrayOfstring xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">';
if(sizeof($languageCodes) > 0){
foreach($languageCodes as $codes) {
$requestXml .= "<string>$codes</string>";
}
} else {
throw new Exception('$languageCodes array is empty.');
}
$requestXml .= '</ArrayOfstring>';
return $requestXml;
}
function xmlTranslateArray($fromLanguage,$toLanguage,$contentType,$inputStrArr) {
$requestXml = "<TranslateArrayRequest>".
"<AppId/>".
"<From>$fromLanguage</From>".
"<Options>" .
"<Category xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\" />" .
"<ContentType xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\">$contentType</ContentType>" .
"<ReservedFlags xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\" />" .
"<State xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\" />" .
"<Uri xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\" />" .
"<User xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\" />" .
"</Options>" .
"<Texts>";
foreach ($inputStrArr as $inputStr) {
$requestXml .= "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">$inputStr</string>";
}
$requestXml .= "</Texts>".
"<To>$toLanguage</To>" .
"</TranslateArrayRequest>";
return $requestXml;
}
}
function get_language_names($locale="en") {
global $list, $apis;
try {
$clientID = $apis['azure']['id'];
$clientSecret = $apis['azure']['key'];
$authUrl = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/";
$scopeUrl = "http://api.microsofttranslator.com";
$grantType = "client_credentials";
$authObj = new AccessTokenAuthentication();
$accessToken = $authObj->getTokens($grantType, $scopeUrl, $clientID, $clientSecret, $authUrl);
$authHeader = "Authorization: Bearer ". $accessToken;
foreach($list['translate'] as $k=>$iso) {
$languageCodes[] = $k;
}
$url = "http://api.microsofttranslator.com/V2/Http.svc/GetLanguageNames?locale=$locale";
$translatorObj = new HTTPTranslator();
$requestXml = $translatorObj->xmlLanguageCodes($languageCodes);
$curlResponse =$translatorObj->curlRequest($url, $authHeader, $requestXml);
$xmlObj = simplexml_load_string($curlResponse);
$i=0;
foreach($xmlObj->string as $language) {
$result[$languageCodes[$i]] = (string)$language;
$i++;
}
return $result;
} catch (Exception $e) {
echo "Exception: " . $e->getMessage() . PHP_EOL;
}
}
function get_translate($array, $from, $to, $html=false) {
global $apis;
try {
$clientID = $apis['azure']['id'];
$clientSecret = $apis['azure']['key'];
$authUrl = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/";
$scopeUrl = "http://api.microsofttranslator.com";
$grantType = "client_credentials";
$authObj = new AccessTokenAuthentication();
$accessToken = $authObj->getTokens($grantType, $scopeUrl, $clientID, $clientSecret, $authUrl);
$authHeader = "Authorization: Bearer ". $accessToken;
$fromLanguage = $from;
$toLanguage = $to;
$inputStrArr = array_values($array);
if($html) {
$contentType = 'text/html';
foreach($inputStrArr as $k=>$item) {
$inputStrArr[$k] = htmlentities($inputStrArr[$k]);
}
} else {
$contentType = 'text/plain';
}
$translatorObj = new HTTPTranslator();
$requestXml = $translatorObj->xmlTranslateArray($fromLanguage,$toLanguage,$contentType,$inputStrArr);
$translateUrl = "http://api.microsofttranslator.com/v2/Http.svc/TranslateArray";
$curlResponse = $translatorObj->curlRequest($translateUrl, $authHeader, $requestXml);
$xmlObj = simplexml_load_string($curlResponse);
foreach($xmlObj->TranslateArrayResponse as $translatedArrObj){
$result[] = (string)$translatedArrObj->TranslatedText;
}
return $result;
} catch (Exception $e) {
echo "Exception: " . $e->getMessage() . PHP_EOL;
}
}
function get_translate_single($input, $from, $to, $html=false) {
global $apis;
try {
$clientID = $apis['azure']['id'];
$clientSecret = $apis['azure']['key'];
$authUrl = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/";
$scopeUrl = "http://api.microsofttranslator.com";
$grantType = "client_credentials";
$authObj = new AccessTokenAuthentication();
$accessToken = $authObj->getTokens($grantType, $scopeUrl, $clientID, $clientSecret, $authUrl);
$authHeader = "Authorization: Bearer ". $accessToken;
$fromLanguage = $from;
$toLanguage = $to;
if($html) {
$contentType = 'text/html';
$input = htmlentities($input);
} else {
$contentType = 'text/plain';
}
# params
$params = "text=".urlencode($input)."&to=".$toLanguage."&from=".$fromLanguage;
$translateUrl = "http://api.microsofttranslator.com/v2/Http.svc/Translate?".$params;
# object
$translatorObj = new HTTPTranslator();
$curlResponse = $translatorObj->curlRequest($translateUrl, $authHeader);
# interprets a string of XML into an object.
$xmlObj = simplexml_load_string($curlResponse);
foreach((array)$xmlObj[0] as $val){
$result = $val;
}
return $result;
} catch (Exception $e) {
echo "Exception: " . $e->getMessage() . PHP_EOL;
}
}
The calls
echo get_translate_single('horse', 'en', 'es'); //this will print 'caballo'
or
echo get_translate(array('horse', 'house'), 'en', 'es'); //this will print array('caballo', 'casa')
That's it, have fun and remember to follow the terms of service.

Related

Connecting to Unleashed API via Woocommerce

I'm trying to connect Woocommerce to Unleashed and have the code for it below. It consistently fails authorisation. It requires a HMAC-SHA256 signature to be generated.
add_action('init', 'register_product');
function register_product(){
register_post_type('product', [
'label' => 'Products Greyville',
'public' => true,
'capability_type' => 'post'
]);
}
function get_products_from_unleashed(){
$current_page = ( ! empty($_POST['current_page']) ) ? $_POST['current_page'] : 1;
$products = [];
$results = wp_remote_get('https://api.unleashedsoftware.com/products/?page=' . $current_page . '&per_page=50');
}
$apiId = "***";
$apiKey = "***";
function getSignature($request, $key) {
return base64_encode(hash_hmac('sha256', $request, $key, true));
}
function getCurl($id, $key, $signature, $endpoint, $requestUrl, $format) {
global $api;
$curl = curl_init($api . $endpoint . $requestUrl);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Content-Type: application/$format",
"Accept: application/$format",
"api-auth-id: $id",
"api-auth-signature: $signature"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
// these options allow us to read the error message sent by the API
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_HTTP200ALIASES, range(400, 599));
return $curl;
}
function get($id, $key, $endpoint, $request, $format) {
$requestUrl = "";
if (!empty($request)) $requestUrl = "?$request";
try {
// calculate API signature
$signature = getSignature($request, $key);
// create the curl object
$curl = getCurl($id, $key, $signature, $endpoint, $requestUrl, $format);
// GET something
$curl_result = curl_exec($curl);
error_log($curl_result);
curl_close($curl);
return $curl_result;
}
catch (Exception $e) {
error_log('Error: ' + $e);
}
}
Please also see: https://apidocs.unleashedsoftware.com/PHP
And: https://apidocs.unleashedsoftware.com/AuthenticationHelp

Gate.io PHP API create order problem => Signature mismatch

I'm not an expert in API development or using signed messages in PHP.
I have however tried to get the GATE.IO v4 API working in my PHP implementation but keep getting "Signature mismatch". I have followed the API documentation for CREATE ORDER available at Gate.io's website here: https://www.gate.tv/docs/developers/apiv4/#create-an-order
I have managed to get the /spot/accounts working, so I know that the key and secret are correct.
Based on the code below I seem to missing something. Probably a tiny error but those are the hardest, right?
Does anyone have any idea what could be the cause of this issue? Would really appreciate your help after having spent 8+ hours trying to get this to work.
<?php
$accessToken = ''; // Access token for OAuth/Bearer authentication
$key = "XXXXXXXXXXXXXXXXXXXXXXX";
$secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$username = ''; // Username for HTTP basic authentication
$password = ''; // Password for HTTP basic authentication
$host = 'https://api.gateio.ws/api/v4'; // The host
$userAgent = 'OpenAPI-Generator/5.26.0/PHP'; // User agent of the HTTP request, set to "OpenAPI-Generator/{version}/PHP" by default
$sResourcePath = "/spot/orders";
$sMethod = "POST"; // POST or GET
$aPayload['currency_pair'] = "DOT_USDT";
$aPayload['price'] = "6.330033";
$aPayload['account'] = "spot";
$aPayload['side'] = "buy";
$aPayload['amount'] = "1";
$aPayload['time_in_force'] = "gtc";
$sBody = json_encode($aPayload);
$aQueryParams = $aPayload;
$aFullPath = parse_url($host . $sResourcePath);
$fullPath = $aFullPath['path'];
$timestamp = time();
$hashedPayload = hash("sha512", ($payload !== null) ? $payload : "");
$fmt = "%s\n%s\n%s\n%s\n%s";
$sQuery = http_build_query($aQueryParams, false);
$signatureString = sprintf($fmt, $sMethod, $fullPath, $sQuery, $hashedPayload, $timestamp);
$signature = hash_hmac("sha512", $signatureString, $secret);
$aSignHeaders = array(
"KEY" => $key,
"SIGN" => $signature,
"Timestamp" => $timestamp);
$aHeaders[] = "KEY: " . $aSignHeaders['KEY'];
$aHeaders[] = "SIGN: " . $aSignHeaders['SIGN'];
$aHeaders[] = "Timestamp: " . $aSignHeaders['Timestamp'];
$aExtraParams['sHttpHeaders'] = $aHeaders;
if ($sMethod == "POST")
{
$sParams = "?" . http_build_query($aQueryParams, false);
}
else
{
$sQuery = "";
}
$sSubmitUrl = $host . $sResourcePath . $sParams;
$sPage = CURL::doRequest($sMethod, $sSubmitUrl, $sParams, $aExtraParams);
$aPage = json_decode($sPage, true);
if ($aPage)
{
$iPage = count($aPage);
}
echo "<pre>";
print_r($aPage);
echo "</pre>";
?>
based on that example request, you should be doing something like this
//path & urls
$host = 'https://api.gateio.ws';
$prefix = '/api/v4';
$path = '/spot/orders';
$fullPath = "$prefix$path";
$method = 'POST';
//your API keys
$api = [
'secret' => 'xxxx'
];
// Your actual data you can easily modify
$payload = [
'currency_pair' => 'DOT_USDT',
'price' => '6.330033',
'account' => 'spot',
'side' => 'buy',
'amount' => '1',
'time_in_force' => 'gtc'
];
//Convert your data to JSON FORMAT
$jsonPayload = json_encode( $payload );
//Hash your JSON DATA
$hashJsonPayload = hash('sha512', $jsonPayload);
$timeStamp = time();
// dunno if this is required
$queryParam = '';
//Create your signature string
$signString="$method\n$fullPath\n$queryParam\n$hashJsonPayload\n$timeStamp";
//Generate the signature
$signHash = hash_hmac('sha512', $signString, $api['secret']);
// Your Actual headers
$headers = [
'Content-Type: application/json',
'Timestamp: '.$timeStamp,
'Key: '.$api['secret'],
'SIGN: '.$signHash
];
Example request using php curl
$ch = curl_init( "$host$fullPath" ); // URL to POST https://api.gateio.ws/api/v4/spot/orders
curl_setopt( $ch, CURLOPT_POSTFIELDS, $jsonPayload ); // set json payload as body here
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); //define header here
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($ch);
curl_close($ch)
echo '<pre>', print_r($result, 1), '</pre>';

trying to get a list of product images using php bigcommerce library

I keep getting NULL in my response while trying to pull images for products. Making a request for list of products works fine. I'm using the version 2 of the Bigcommerce API. What am I missing?
My code is below:
$product_id = 82;
$organizationAccount = array(
"username" => "stores/xxxx",
"user_token" => "xxxxx"
);
$resource = 'http://api.bigcommerce.com/stores/xxxx/api/v2/products/'.$product_id.'/images.json';
$response = sendRequest($resource, 'GET', 'user_token'); //This gives null
Send Request function
function sendRequest($url, $method, $userToken, $postFields = null, $queryData = null){
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
if( $method == "PUT" ){
curl_setopt($curlHandle, CURLOPT_HEADER, true);
}
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, $method);
$httpHeader = array('Content-Type: application/json');
$url = (strpos($url, "http") !== false ) ? str_replace("http", "https", $url) : "https://" . $url;
if ($method == "POST" || $method == "PUT" || $method == "DELETE") {
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_POST, true);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $postFields);
} elseif ($method == "GET") {
$url = (is_null($queryData)) ? $url : $url . "?" . http_build_query($queryData);
curl_setopt($curlHandle, CURLOPT_URL, $url);
}
if (!is_null($userToken)) {
$httpHeader[] = 'X-Auth-Client: ' . BC_CLIENT_ID; //Client id
$httpHeader[] = 'X-Auth-Token: ' . $userToken;
//curl_setopt($curlHandle);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $httpHeader);
}
$response = curl_exec($curlHandle);
return json_decode($response, true);
}
the mistake was from the endpoint url it is supposed to be
$resource = 'http://api.bigcommerce.com/stores/xxxx/v2/products/'.$product_id.'/images.json';
thanks

how to get values from big commerce using php api

<?php
/**
*Class to instantiate different api connections
*
* #author Adam Bilsing <adambilsing#gmail.com>
*/
class connection
{
/**
*public and private variables
*
* #var string stores data for the class
*/
static public $path;
static private $user;
static private $token;
static private $headers;
/**
* Sets $_path, $_user, $_token, $_headers upon class instantiation
*
* #param $user, $path, $token required for the class
* #return void
*/
public function __construct($user, $path, $token) {
$path = explode('/api/v2/', $path);
$this->_path = $path[0];
$this->_user = $user;
$this->_token = $token;
$encodedToken = base64_encode($this->_user.":".$this->_token);
$authHeaderString = 'Authorization: Basic ' . $encodedToken;
$this->_headers = array($authHeaderString, 'Accept: application/json','Content-Type: application/json');
}
public static function http_parse_headers( $header )
{
$retVal = array();
$fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header));
foreach( $fields as $field ) {
if( preg_match('/([^:]+): (.+)/m', $field, $match) ) {
$match[1] = preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1])));
if( isset($retVal[$match[1]]) ) {
$retVal[$match[1]] = array($retVal[$match[1]], $match[2]);
} else {
$retVal[$match[1]] = trim($match[2]);
}
}
}
if ($retVal['X-Bc-Apilimit-Remaining'] <= 100) {
sleep(300);
}
}
public function error($body, $url, $json, $type) {
global $error;
if (isset($json)) {
$results = json_decode($body, true);
$results = $results[0];
$results['type'] = $type;
$results['url'] = $url;
$results['payload'] = $json;
$error = $results;
} else {
$results = json_decode($body, true);
$results = $results[0];
$results['type'] = $type;
$results['url'] = $url;
$error = $results;
}
}
/**
* Performs a get request to the instantiated class
*
* Accepts the resource to perform the request on
*
* #param $resource string $resource a string to perform get on
* #return results or var_dump error
*/
public function get($resource) {
$url = $this->_path . '/api/v2' . $resource;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->_headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_HTTPGET, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$body = substr($response, $header_size);
self::http_parse_headers($headers);
curl_close ($curl);
if ($http_status == 200) {
$results = json_decode($body, true);
return $results;
} else {
$this->error($body, $url, null, 'GET');
}
}
/**
* Performs a put request to the instantiated class
*
* Accepts the resource to perform the request on, and fields to be sent
*
* #param string $resource a string to perform get on
* #param array $fields an array to be sent in the request
* #return results or var_dump error
*/
public function put($resource, $fields) {
$url = $this->_path . '/api/v2' . $resource;
$json = json_encode($fields);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->_headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$body = substr($response, $header_size);
self::http_parse_headers($headers);
curl_close($curl);
if ($http_status == 200) {
$results = json_decode($body, true);
return $results;
} else {
$this->error($body, $url, $json, 'PUT');
}
}
/**
* Performs a post request to the instantiated class
*
* Accepts the resource to perform the request on, and fields to be sent
*
* #param string $resource a string to perform get on
* #param array $fields an array to be sent in the request
* #return results or var_dump error
*/
public function post($resource, $fields) {
global $error;
$url = $this->_path . '/api/v2' . $resource;
$json = json_encode($fields);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->_headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec ($curl);
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$body = substr($response, $header_size);
self::http_parse_headers($headers);
curl_close ($curl);
if ($http_status == 201) {
$results = json_decode($body, true);
return $results;
} else {
$this->error($body, $url, $json, 'POST');
}
}
/**
* Performs a delete request to the instantiated class
*
* Accepts the resource to perform the request on
*
* #param string $resource a string to perform get on
* #return proper response or var_dump error
*/
public function delete($resource) {
$url = $this->_path . '/api/v2' . $resource;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->_headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$body = substr($response, $header_size);
self::http_parse_headers($headers);
curl_close ($curl);
if ($http_status == 204) {
return $http_status . ' DELETED';
} else {
$this->error($body, $url, null, 'DELETE');
}
}
}
?>
get('RESOURCE');
$store->delete('RESOURCE');
$store->post('RESOURCE', $fields);
$store->put('RESOURCE', $fields);
?>
If i run these code i m getting error like this
( ! ) Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in D:\wamp\www\Bigcommerce\connection.php on line 39
Notice: Undefined variable: fields in D:\wamp\www\Bigcommerce\singlepage.php on line 5
any one pls help me to solve this problem

How can I login with facebook via quickblox (PHP)

I read this section http://quickblox.com/developers/Social_Networks_Integration_Manual
But I don't know what to do.If somebody know please help me :)
I was tried with hybridauth I have connection with facebook (my API) hybridauth return to me user information.I create user in quickblox with random password and facebook email and simulate login but this is bad because quickblox in this way don't return to me token and if I want to edit profil I can't....
if( isset( $_GET["login"] ) ){
try{
$hybridauth = new Hybrid_Auth( $config );
$adapter = $hybridauth->authenticate( "facebook" );
$user_profile = $adapter->getUserProfile();
}
catch( Exception $e ){
die( "<b>got an error!</b> " . $e->getMessage() );
}
$token = $adapter->getAccessToken();
//$token['access_token'];
$nonce = rand();
$timestamp = time();
$signature_string = "application_id=".APPLICATION_ID."&auth_key=".AUTH_KEY."&nonce=".$nonce."&timestamp=".$timestamp;
$signature = hash_hmac('sha1', $signature_string , AUTH_SECRET);
// Build post body
//$post_body = "application_id=" . APPLICATION_ID . "&auth_key=".AUTH_KEY."&timestamp=".$timestamp."&nonce=".$nonce."&signature=".$signature."&user[email]=" . $user_profile->email . "&provider=facebook&scope=friends_status,read_mailbox,photo_upload&keys[token]=".$token['access_token'];
$post_body = http_build_query(array(
'application_id' => APPLICATION_ID,
'auth_key' => AUTH_KEY,
'timestamp' => $timestamp,
'nonce' => $nonce,
'signature' => $signature
));
$post_body = "application_id=" . APPLICATION_ID . "&auth_key=" . AUTH_KEY . "&timestamp=" . $timestamp . "&nonce=" . $nonce . "&signature=" . $signature."&user[login]=&user[email]=&user[password]=&provider=facebook&scope=friends_status,read_mailbox,photo_upload&keys[token]=".$token['access_token']."&keys[secret]=";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, QB_API_ENDPOINT . '/' . QB_PATH_SESSION); // Full path is - https://api.quickblox.com/session.json
curl_setopt($curl, CURLOPT_POST, true); // Use POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body); // Setup post body
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response
$response = curl_exec($curl);
dump($response);
if ($response) {
return $response . "\n";
} else {
$error = curl_error($curl). '(' .curl_errno($curl). ')';
return $error . "\n";
}
This don't work...this is shity they don't have examples :O
You should add 'provider=facebook' to your post_body and signature_string
After this - QuickBlox will return HTML page with Facebook login dialog, which you should render to your end users