How to update user profile picture in QuickBlox using php api? - php

How to update user profile picture in Quickblox using php codeigntier ?
Documentation found at
http://quickblox.com/developers/Users

after found rest api i have found the solution for how to upload profile picture to quickblox user.
there are three 3 steps for uploading content as per quickblox rest api
First you generate token from the quickblox and then perform these 3 steps
Create file
https://quickblox.com/developers/Content#Create_a_file
$strFilename = '2.jpeg';
$post_body = http_build_query(array(
'blob[content_type]' => 'image/jpeg',
'blob[name]' =>$strFilename,
));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, QB_API_ENDPOINT.'blobs.json');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
'QuickBlox-REST-API-Version: 0.1.0',
'QB-Token: ' . $token
));
$response = curl_exec($curl);
$error = curl_error($curl);
if ($response) {
return $response;
} else {
return false;
}
curl_close($curl);
After this curl call you have got the response and in response got the response like this
[blob] => Array
(
[id] => 7178102
[uid] => f9cc9d7938c4468f8bdccdcb68fb5d8c00
[content_type] => image/jpeg
[name] => 2.jpeg
[size] =>
[created_at] => 2017-02-07T10:35:38Z
[updated_at] => 2017-02-07T10:35:38Z
[ref_count] => 1
[blob_status] =>
[set_completed_at] =>
[public] => 1
[last_read_access_ts] =>
[lifetime] => 8600
[account_id] => 56721
[app_id] =>
[blob_object_access] => Array
(
[id] => 7178102
[blob_id] => 7178102
[expires] => 2017-02-07T11:35:38Z
[object_access_type] => Write
[params] => https://qbprod.s3.amazonaws.com/?Content-Type=image%2Fjpeg&Expires=Tue%2C%2007%20Feb%202017%2011%3A35%3A38%20GMT&acl=public-read&key=f9cc9d7938c4468f8bdccdcb68fb5d8c00&policy=eyJleHBpcmF0aW9uIjoiMjAxNy0wMi0wN1QxMTozNTozOFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJxYnByb2QifSx7ImFjbCI6InB1YmxpYy1yZWFkIn0seyJDb250ZW50LVR5cGUiOiJpbWFnZS9qcGVnIn0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiIyMDEifSx7IkV4cGlyZXMiOiJUdWUsIDA3IEZlYiAyMDE3IDExOjM1OjM4IEdNVCJ9LHsia2V5IjoiZjljYzlkNzkzOGM0NDY4ZjhiZGNjZGNiNjhmYjVkOGMwMCJ9LHsieC1hbXotY3JlZGVudGlhbCI6IkFLSUFJWTdLRk0yM1hHWEo3UjdBLzIwMTcwMjA3L3VzLWVhc3QtMS9zMy9hd3M0X3JlcXVlc3QifSx7IngtYW16LWFsZ29yaXRobSI6IkFXUzQtSE1BQy1TSEEyNTYifSx7IngtYW16LWRhdGUiOiIyMDE3MDIwN1QxMDM1MzhaIn1dfQ%3D%3D&success_action_status=201&x-amz-algorithm=AWS4-HMAC-SHA256&x-amz-credential=AKIAIY7KFM23XGXJ7R7A%2F20170207%2Fus-east-1%2Fs3%2Faws4_request&x-amz-date=20170207T103538Z&x-amz-signature=5e236c3da60a922951c8ab6281ae82af3a88e37c15d8630ad6ff590610a87fd8
)
)
Upload file
so you have to used the params url parameters and make another call for uploading file
$strFilename = '2.jpeg';
$url = 'https://qbprod.s3.amazonaws.com/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'Content-Type' => $arr['Content-Type'],
'Expires'=>$arr['Expires'],
'acl'=>$arr['acl'],
'key'=>$arr['key'],
'policy'=>$arr['policy'],
'success_action_status'=>$arr['success_action_status'],
'x-amz-algorithm'=>$arr['x-amz-algorithm'],
'x-amz-credential'=>$arr['x-amz-credential'],
'x-amz-date'=>$arr['x-amz-date'],
'x-amz-signature'=>$arr['x-amz-signature'],
'file' => new CurlFile('2.jpeg', $arr['Content-Type'], $strFilename)
));
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 204) {
echo 'Success!';
} else {
$error = substr($response, strpos($response, '<Code>') + 6);
echo substr($error, 0, strpos($error, '</Code>'));
}
return $response;
so by using this code your content file will be uploaded and you got the location of the file and used as profile picture or etc .
Declare file
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.quickblox.com/blobs/" . $strId . "/complete.xml"); // strId is blod id return by 1 step
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "blob[size]=10000"); //your file size
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$headers = array();
$headers[] = "Quickblox-Rest-Api-Version: 0.1.0";
$headers[] = "Qb-Token: " . $token;
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
Please let me know the any issue regards the same.
Thanks

Related

Amazon Advertising API - Error code 422 while POST keywords

I'm getting this error using Amazon Advertising API while trying to create new keywords:
"code":"422"
This is my PHP Code:
curl_setopt($ch, CURLOPT_URL, $std_url . "/v2/sp/keywords");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data_string = array(
"campaignId" => "111111111111",
"adGroupId" => "2222222222222",
"state" => "enabled",
"keywordText" => "YetAnotherKeyword",
"matchType" => "broad",
"bid" => "0.05");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$headers = array();
$headers[] = "Content-Type:application/json";
$headers[] = ("Authorization: Bearer " . $accesstoken);
$headers[] = ("Amazon-Advertising-API-ClientId: ". $client);
$headers[] = ("Amazon-Advertising-API-Scope: " . $API_Scope);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
echo $result;
I've got the solution. The array needs to be modified like this:
$data_string = array(array(
"campaignId" => "111111111111",
"adGroupId" => "2222222222222",
"state" => "enabled",
"keywordText" => "YetAnotherKeyword",
"matchType" => "broad",
"bid" => "0.05"));

Get size of remote file from google drive URL

Is there a way to get the size of a remote file https://drive.google.com/uc?export=download&id=54fs54dg45f1f112f2 before downloading the file?
You could make a curl request to get sizeBytes.
<?php
$id = '0ByzJffaEk18uN2ZLeGlIRGVOaDJmWS1WU1RUN3d***';
$ch = curl_init('https://drive.google.com/uc?id='.$id.'&export=download');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, []);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
$object = json_decode(str_replace(')]}\'', '', $result));
print_r($object);
Result:
stdClass Object
(
[disposition] => SCAN_CLEAN
[downloadUrl] => https://doc-08-8o-docs.googleusercontent.com/docs/...
[fileName] => filename.sh
[scanResult] => OK
[sizeBytes] => 4936
)

Not able to send push notifications in android even after getting success1 through my PHP script

My PHP script looks like this:
<?php
$reg_id = "d8Sq53-gteU:APA91bGFcbSrcWY6J9fVBhUJVci4YHgktjoTOTbRjMXi7uY6ss-kLM39GpSt16cMmwsm2k4n9y3_YrcyBT7o9bpsN2QFS_bVceMcV-WThbThXMCWSiwaaP7p5LAJlb_01mzPbHb6xq1X1";
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'to' => $reg_id ,
'priority' => "high",
'data' => array(
"title" => "Android Learning",
"message" => "Test",
"image"=> "dsdsd",
"tag" => "dsdsd"
)
);
$headers = array(
'Authorization:key = AIzaSyC6ld4WBRmk8W6DZgMqevu1Na3dcQdQDBIA ',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
print_r($result);die;
?>
This is the response I am getting:
{"multicast_id":7558168491201020947,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1484883356821016%9bd11ceef9fd7ecd"}]}
But in Android I am unable to get the data that I am posting through the notification. Is there a problem with PHP script that I am using, Is the response that I am getting through PHP script correct. Or there is some problem with the android code. Can anyone help me please.
**Please check below .php file it will working fine for me.**
**You just need to pass firebase id "fcm_token" parameter to this php file**.
<?php
require_once __DIR__ . '/config.php';
// need to pass Firebase Register ID.
$registration_ids=$_POST["fcm_token"];
$title='hello';
$message='Please check the Details';
$is_background=FALSE;
$image='';
$payload='Its Payload';
$timestamp='10:15';
$arr = array('title' => $title, 'is_background' => $is_background, 'message' => $message, 'timestamp' => $timestamp, 'image' => $image,'payload'=> $payload);
$arr1 = array('data' => $arr);
$json = $arr1;
$fields = array('to' => $registration_ids,'data' => $json,);
//echo json_encode($fields);
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Authorization: key=' . FIREBASE_API_KEY,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
echo 'its Not done bro';
}else{
echo 'its done bro';
}
// Close connection
curl_close($ch);
?>
Finally got the code which is working for me-
`
$filename = 'Fav_Icon.png';
$title = "thisis title";
$coupon_id = 1;
$url = 'https://fcm.googleapis.com/fcm/send';
$msg = array
(
'message' => 'We have added a new Coupon. Please have a look !!!',
'title' => $title,
'smallIcon' => base_url().'uploads/icons/'.$filename,
'type' => 'Coupon',
'coupon_id' => $coupon_id
);
$res = array();
$res['data']['title'] = "Coupon Name";
$res['data']['message'] = "We have added a new Coupon. Please have a look !!!";
$res['data']['image'] = base_url().'uploads/icons/'.$filename;
$res['data']['tag'] = "Coupon";
$res['data']['coupon_id'] = $coupon_id;
$fields = array(
'to' => $reg_id ,
'priority' => "high",
'data' => $res
);
$headers = array(
'Authorization:key = AIzaSyC6ld4WBRmk8W6DZgMqevu1Na3dcQdQDBIER ',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
print_r($result);
return $result;
?>`

get curl request to eBay Post Order API giving empty string (PHP)

GET /post-order/v2/casemanagement/{caseId} call of eBay Post Order API giving an empty string. Can anyone clear out where does my code go wrong? Am I passing the headers correctly? Especially is the syntax of authorization correct?
<?php
error_reporting(E_ALL); // Turn on all errors, warnings and notices for easier debugging
//Seller Authorization Token
$userAuthToken= 'Authorization:TOKEN abc123';
//Endpoint URL to Use
$url = "https://api.ebay.com/post-order/v2/casemanagement/xyz";
//Initializle cURL
$connection = curl_init();
//Set Endpoint URL
curl_setopt($connection,CURLOPT_URL,$url);
//Set HTTP Method
curl_setopt($connection, CURLOPT_HTTPGET, true);
//Create Array of Required Headers
$headers = array();
$headers[] = $userAuthToken;
$headers[] = 'Content-Type:application/json';
$headers[] = 'X-EBAY-C-MARKETPLACE-ID:EBAY-DE';
//var_dump($headers);
//set the headers using the array of headers
curl_setopt($connection,CURLOPT_HTTPHEADER,$headers);
//set it to return the transfer as a string from curl_exec
curl_setopt($connection,CURLOPT_RETURNTRANSFER,1);
//stop CURL from verifying the peer's certificate
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
//Execute the Request
$response = curl_exec($connection);
//close the connection
curl_close($connection);
var_dump($response);
Try this code it is working fine for me.
<?php
// Your ID and token
$authToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
// The data to send to the API
$post_data = json_encode(array("legacyOrderId"=>"110181400870-27973775001"));
$url = 'https://api.sandbox.ebay.com/post-order/v2/cancellation/check_eligibility';
//Setup cURL
$header = array(
'Accept: application/json',
'Authorization: TOKEN '.$authToken,
'Content-Type: application/json',
'X-EBAY-C-MARKETPLACE-ID: EBAY-UK'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if(curl_errno($ch)){
echo "ERROR:".curl_error($ch);
}
curl_close($ch);
echo json_decode($response,true);
?>
Response:
Array
(
[legacyOrderId] => 110181400870-27973775001
[eligible] => 1
[failureReason] => Array
(
)
[itemEligibilityResult] => Array
(
[0] => Array
(
[itemId] => 110181400870
[transactionId] => 34573775001
[eligible] => 1
[failureReason] => Array
(
)
)
)
[eligibleCancelReason] => Array
(
[0] => OUT_OF_STOCK_OR_CANNOT_FULFILL
[1] => BUYER_CANCEL_OR_ADDRESS_ISSUE
)
)
ADD
curl_setopt($connection, CURLOPT_HEADER, 1);
To return the headers and see what your problem might be.
I also don't know if it matters but my headers array looks like:
$headers = array (
'Authorization: ' . "TOKEN $token",
'Content-Type: ' . 'application/json',
'X-EBAY-C-MARKETPLACE-ID: ' . 'EBAY-US',
'Accept: ' . 'application/json',
);
So you can see there is a space after the colon.

Send notification to specific device using Pushwoosh and Php

Has any one had any success in using Pushwoosh remote api to send custom notifications to a specific device? I have went over their documentation to set this up, but the notification keeps going out to all devices. What am I doing wrong here? Thanks in advance.
<?php
define('PW_AUTH', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
define('PW_APPLICATION', 'XXXXXX-XXXXXX');
define('PW_DEBUG', true);
function pwCall($method, $data = array()) {
$url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
$request = json_encode(['request' => $data]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if (defined('PW_DEBUG') && PW_DEBUG) {
print "[PW] request: $request\n";
print "[PW] response: $response\n";
print "[PW] info: " . print_r($info, true);
}
}
pwCall('createMessage', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'notifications' => array(
array(
'send_date' => 'now',
'content' => 'Send this content to user',
)
),
'devices' => array('2lksdflkje96a4389f796173fakeae938device95ajkdh8709843') //Optional. Not more than 1000 tokens in an array. If set, message will only be delivered to the devices in the list. Ignored if the applications group is used
)
);
?>
You must specify devices list into notifications array. Please see right request below (Also Pushwoosh API documentation available here https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-Method-messages-create)
<?php
define('PW_AUTH', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
define('PW_APPLICATION', 'XXXXXX-XXXXXX');
define('PW_DEBUG', true);
function pwCall($method, $data = array()) {
$url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
$request = json_encode(['request' => $data]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if (defined('PW_DEBUG') && PW_DEBUG) {
print "[PW] request: $request\n";
print "[PW] response: $response\n";
print "[PW] info: " . print_r($info, true);
}
}
pwCall('createMessage', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'notifications' => array(
array(
'send_date' => 'now',
'content' => 'Send this content to user',
'devices' => array('2lksdflkje96a4389f796173fakeae938device95ajkdh8709843') //Optional. Not more than 1000 tokens in an array. If set, message will only be delivered to the devices in the list. Ignored if the applications group is used
)
),
)
);
?>

Categories