My API randomly returns nothing - php

I have some troubles with a custom written API.
It happens when I do an API call, it randomly returns nothing. This is now temporary fixed by doing the same API call until something is returned.
The API calls are always the same and the code itself (SDK and API) does not throw any errors.
I'm thinking of a connection problem?
Is there anyone who has an idea how to fix this properly?
SDK Code:
function doGetRequest($request, $params = array()) {
$request = 'http://www.xxx.be/api/nl/'.$request.'?'.http_build_query($params);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $request,
));
$resp = curl_exec($curl);
curl_close($curl);
return json_decode($resp);
}//doGetRequest
API Code:
public function getCompanyIdByUserId($userId) {
$sql = '
SELECT
company_member_company_id
FROM
ka_company_members
WHERE
company_member_member_id = ?
';
return db::getValue($sql, $userId);
}//getCompanyIdByUserId
Curl_info gives me this when there's nothing returned
["url"] => string(123) "http://xxx/nl/urldata/mijn_webcasts/43?key=xxx"
["content_type"]=>
string(29) "text/html; charset=iso-8859-1"
["http_code"]=>
int(500)
["header_size"]=>
int(199)
["request_size"]=>
int(154)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(0)
["redirect_count"]=>
int(0)
["total_time"]=>
float(0.005005)
["namelookup_time"]=>
float(1.4E-5)
["connect_time"]=>
float(4.8E-5)
["pretransfer_time"]=>
float(7.5E-5)
["size_upload"]=>
float(0)
["size_download"]=>
float(603)
["speed_download"]=>
float(120479)
["speed_upload"]=>
float(0)
["download_content_length"]=>
float(603)
["upload_content_length"]=>
float(0)
["starttransfer_time"]=>
float(0.004986)
["redirect_time"]=>
float(0)
["redirect_url"]=>
string(0) ""
["certinfo"]=>
array(0) {
}
}

Related

Photo is rotated on upload. PHP ImageMagick

the photo before loading in the preview is correct, but on the server it is already saved sideways
Image save code:
public function postUploadImage($path, $id) {
$img = new Imagick($path);
$profiles = $img->getImageProfiles("icc", true);
$img->stripImage();
if(!empty($profiles))
$img->profileImage("icc", $profiles['icc']);
$img->cropThumbnailImage(500, 500);
$img->setImageCompressionQuality(80);
$img->writeImage($_SERVER['DOCUMENT_ROOT'] . '/public/materials/'.$id.'.jpg');
$img->clear();
}
I kind of understand that the problem is EXIF, but how to get rid of them if stripImage () does not work
Thanks for wathing!
If i try used var_dump(exif_read_data($path)); he return
array(7) {
["FileName"]=>
string(9) "phpv0IOKS"
["FileDateTime"]=>
int(1615462769)
["FileSize"]=>
int(99279)
["FileType"]=>
int(2)
["MimeType"]=>
string(10) "image/jpeg"
["SectionsFound"]=>
string(0) ""
["COMPUTED"]=>
array(4) {
["html"]=>
string(24) "width="960" height="540""
["Height"]=>
int(540)
["Width"]=>
int(960)
["IsColor"]=>
int(1)
}
}

Express Checkout DPaypal PHP working live but failing in sandbox

I'm using this library:
https://github.com/amirduran/duranius-paypal-rest-api-php-library
In live mode everything is fine, but when I try to use sandbox I just get: int(35)
$requestParameters = array(
"USER" => $this->username,
"PWD" => $this->password,
"SIGNATURE" => $this->apiSignature,
"METHOD" => $method,
"VERSION" => $this->apiVersion,
);
$requestParameters+=$requestData;
$finalRequest = http_build_query($requestParameters);
$ch = curl_init();
$this->curl=$ch;
$curlOptions=$this->getcURLOptions();
$curlOptions[CURLOPT_POSTFIELDS]=$finalRequest;
curl_setopt_array($ch, $curlOptions);
$serverResponse = curl_exec($ch);
curl_getinfo($ch) result:
array(26) {
["url"]=>
string(37) "https://api-3t.sandbox.paypal.com/nvp"
["content_type"]=>
NULL
["http_code"]=>
int(0)
["header_size"]=>
int(0)
["request_size"]=>
int(0)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(1)
["redirect_count"]=>
int(0)
["total_time"]=>
float(0.228482)
["namelookup_time"]=>
float(0.027594)
["connect_time"]=>
float(0.175784)
["pretransfer_time"]=>
float(0)
["size_upload"]=>
float(0)
["size_download"]=>
float(0)
["speed_download"]=>
float(0)
["speed_upload"]=>
float(0)
["download_content_length"]=>
float(-1)
["upload_content_length"]=>
float(-1)
["starttransfer_time"]=>
float(0)
["redirect_time"]=>
float(0)
["redirect_url"]=>
string(0) ""
["primary_ip"]=>
string(11) "173.0.82.83"
["certinfo"]=>
array(0) {
}
["primary_port"]=>
int(443)
["local_ip"]=>
string(13) "192.168.1.100"
["local_port"]=>
int(53117)
}
If I just change the url to https://api-3t.paypal.com/nvp I'll get a successful or failure response.
I already checked all credentials, cleaned all the cookies, logged in into real and sandbox account and I had used it some months ago without any issue.
Thank you!
Apparently the problem was with openssl version.
I solved it by installing the last version of Mamp (4.1.1) with php 7.1 on my computer and changing the version of php on the server also. Everything working now! ^.^

Curl is not working on my live server

I have using sms gateway api on my server
$live_url = "http://sms6.routesms.com:8000/bulksms/bulksms?username=XXX&password=XXX&type=1&dlr=0&destination=XXX&source=routesms&message=CurlSecond";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $live_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
For this,
if i do var_dump(curl_exec($ch));, It is showing false
if i do var_dump(curl_getinfo($ch));, It is showing like
array(26) { ["url"]=> string(153) "http://sms6.routesms.com:8000/bulksms/bulksms?username=XXX&password=XXX&type=1&dlr=0&destination=XXX&source=routesms&message=CurlSecond" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(62.345893) ["namelookup_time"]=> float(0.08692) ["connect_time"]=> float(0) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) ["certinfo"]=> array(0) { } ["primary_ip"]=> string(0) "" ["primary_port"]=> int(0) ["local_ip"]=> string(0) "" ["local_port"]=> int(0) ["redirect_url"]=> string(0) "" }
What i have to do?
I can't understand the issue?
I have tried one more way, Instead of curl, i have used
file($live_url);
This is also not working
Please cross check is curl is installed on your server, if curl is not installed try following.
If it is ubontu server RUN
sudo apt-get install php5-curl
Restart Your Server
sudo service apache2 restart
Alternatively, if you are using php-fpm, you'll need to restart php5-fpm instead
sudo service php5-fpm restart
Hope this works ...

Editing Contact Results In "Not Found"

I have working PHP code to create a Google contact via their v3 API. However, when it comes time to edit (update) the contact I cannot seem to get it to do the update. I keep getting a "Not Found" back in the update response. Any ideas why???
Here is my code.
$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPE);
$client->setClientId(CLIENT_ID);
$client->setClientSecret(CLIENT_SECRET);
$client->setRedirectUri(REDIRECT_URI);
$client->setAccessToken($token);
$xml = <<<END_XML
<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:gContact='http://schemas.google.com/contact/2008'>
<atom:content type='text'>{$content}</atom:content>
</atom:entry>
END_XML;
$request = new Google_Http_Request("https://www.google.com/m8/feeds/contacts/{$account}/full/{$contact['id']}");
$request = $client->getAuth()->sign($request);
$request->setRequestMethod("POST");
$request->setPostBody($xml);
$request->setRequestHeaders(array('content-length' => strlen($xml), 'GData-Version'=> '3.0','content-type'=>'application/atom+xml; charset=UTF-8; type=feed'));
$response = $client->getIo()->executeRequest($request);
Here is a var_dump of my request (data masked with xxx):
object(Google_Http_Request)#5 (14) {
["batchHeaders":"Google_Http_Request":private]=>
array(3) {
["Content-Type"]=>
string(16) "application/http"
["Content-Transfer-Encoding"]=>
string(6) "binary"
["MIME-Version"]=>
string(3) "1.0"
}
["queryParams":protected]=>
array(0) {
}
["requestMethod":protected]=>
string(4) "POST"
["requestHeaders":protected]=>
array(4) {
["authorization"]=>
string(90) "Bearer ya29.vQDJSs7ZxzBG8eN05Er6KiwutMf0K_uNKyuNUu4s5jd9XL4oA3o_SsikhUeIGzRoVtacYwlVVFcEYg"
["content-length"]=>
int(392)
["gdata-version"]=>
string(3) "3.0"
["content-type"]=>
string(46) "application/atom+xml; charset=UTF-8; type=feed"
}
["baseComponent":protected]=>
string(22) "https://www.google.com"
["path":protected]=>
string(65) "/m8/feeds/contacts/events#xxx/full/1603b8310ac9f5ca"
["postBody":protected]=>
string(392) "<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:gContact='http://schemas.google.com/contact/2008'>
<id>http://www.google.com/m8/feeds/contacts/events%40xxx/base/1603b8310ac9f5ca</id>
<atom:content type='text'>Notes Test Data</atom:content>
</atom:entry>"
["userAgent":protected]=>
NULL
["canGzip":protected]=>
NULL
["responseHttpCode":protected]=>
NULL
["responseHeaders":protected]=>
NULL
["responseBody":protected]=>
NULL
["expectedClass":protected]=>
NULL
["accessKey"]=>
NULL
}
Here is a var_dump of my response:
array(3) {
[0]=>
string(9) "Not Found"
[1]=>
array(12) {
["cache-control"]=>
string(46) "no-cache, no-store, max-age=0, must-revalidate"
["pragma"]=>
string(8) "no-cache"
["expires"]=>
string(29) "Fri, 01 Jan 1990 00:00:00 GMT"
["date"]=>
string(29) "Fri, 14 Nov 2014 00:13:58 GMT"
["vary"]=>
string(15) "Origin
X-Origin"
["content-type"]=>
string(24) "text/html; charset=UTF-8"
["x-content-type-options"]=>
string(7) "nosniff"
["x-frame-options"]=>
string(10) "SAMEORIGIN"
["x-xss-protection"]=>
string(13) "1; mode=block"
["server"]=>
string(3) "GSE"
["alternate-protocol"]=>
string(15) "443:quic,p=0.01"
["transfer-encoding"]=>
string(7) "chunked"
}
[2]=>
int(404)
}
Since https://developers.google.com/google-apps/contacts/v3/http-update,
that means request to the Contacts API must be sent with https:// instead of http:// now, have you noticed you are using
http://www.google.com/m8/feeds/contacts/events%40xxx/base/1603b8310ac9f5ca
rather than
https://www.google.com/m8/feeds/contacts/events%40xxx/base/1603b8310ac9f5ca
in the var_dump of my request code.
I think you need to change
$request->setRequestMethod("POST");
to
$request->setRequestMethod("PUT");

Publish on Twitter using PHP (OAuth) Abraham Williams

I'm at a certain time researching how to make the publication on twitter via programming, but until then I got the code I will show below, only that even with everything set up correctly still not sending, does anyone have any suggestions for settings I must be forgetting to do so sending is completed?
Remembering that I'm using the TwiterrOAuth Abraham Williams, already applied for the 1.1 API. (Latest version of GIT)
Below is the code.
<?php
// Insert your keys/tokens
$consumerKey = 'CONSUMER';
$consumerSecret = 'CSECRET';
$OAuthToken = 'TOKEN';
$OAuthSecret = 'TSECRET';
// Full path to twitterOAuth.php (change OAuth to your own path)
require_once('twitteroauth.php');
// create new instance
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret);
// Your Message
$message = "This is a test message.";
// Send tweet
$tweet->post('statuses/update', array('status' => "$message"));
?>
Have researched in several posts here on the site and brought me no solution to my problem. Remembering that you are not returning anything, just nothing happens.
My application is setup as read and write on Twitter.
The $tweet->post return false if i check it.
This is what var_dump($tweet) returns
object(TwitterOAuth)#1 (13) {
["http_code"]=> int(0)
["url"]=> string(48) "https://api.twitter.com/1.1/statuses/update.json"
["host"]=> string(28) "https://api.twitter.com/1.1/"
["timeout"]=> int(30)
["connecttimeout"]=> int(30)
["ssl_verifypeer"]=> bool(false)
["format"]=> string(4) "json"
["decode_json"]=> bool(true)
["http_info"]=> array(20) {
["url"]=> string(48) "https://api.twitter.com/1.1/statuses/update.json"
["content_type"]=> NULL
["http_code"]=> int(0)
["header_size"]=> int(0)
["request_size"]=> int(0)
["filetime"]=> int(-1)
["ssl_verify_result"]=> int(0)
["redirect_count"]=> int(0)
["total_time"]=> float(30.02972)
["namelookup_time"]=> float(0.058814)
["connect_time"]=> float(0)
["pretransfer_time"]=> float(0)
["size_upload"]=> float(0)
["size_download"]=> float(0)
["speed_download"]=> float(0)
["speed_upload"]=> float(0)
["download_content_length"]=> float(-1)
["upload_content_length"]=> float(-1)
["starttransfer_time"]=> float(0)
["redirect_time"]=> float(0) }
["useragent"]=> string(25) "TwitterOAuth v0.2.0-beta2"
["sha1_method"]=> object(OAuthSignatureMethod_HMAC_SHA1)#2 (0) { }
["consumer"]=> object(OAuthConsumer)#3 (3) {
["key"]=> string(22) "uqZ5yUGoofxxxxxxxxxxx"
["secret"]=> string(40) "fGpJERhrIAB9RIyQEExxxxxxxxxxx"
["callback_url"]=> NULL
}
["token"]=> object(OAuthConsumer)#4 (3) {
["key"]=> string(50) "49596683-Sxxxxxxxxxxxxxxxxxx"
["secret"]=> string(40) "v3Q6pAeE4t1YXaGxxxxxxxxxxxxxx"
["callback_url"]=> NULL
}
}
The $host variable.
public $host = "https://api.twitter.com/1.1/";
Try adding ..
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret)
$tweet->get('account/verify_credentials'); //<--- Add this.

Categories