Download Whatsapp Business Media Image API - php

I am Using Whatsapp Media Api to get Image send from user to business number using webhooks and i also get the Image ID and url and Image as well in Postman but when I use that curl request made from Postman it alwasy shows facebook error:
Sorry, something went wrong.
We're working on it and we'll get it fixed as soon as we can.
But its working fine in Postman what am i doing wrong?
<?php
$ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.16 (KHTML, like Gecko) \
Chrome/24.0.1304.0 Safari/537.16';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'Image_URL_from_Api',
CURLOPT_USERAGENT => $ua,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer My_Token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

OK, I've got the answer I needed to give the user_agent value which is in postman it is automatically putting CURLOPT_USERAGENT => 'PostmanRuntime/7.26.10' in the header but for curl, I've added CURLOPT_USERAGENT => 'curl/7.64.1', and it worked.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent

Related

Why curl giving 1020 error while postman giving response [duplicate]

This question already has an answer here:
curl 1020 error when trying to scrape page using bash script
(1 answer)
Closed yesterday.
`I have sent a GET (Also POST) method to get data from api but the response is error 1020 and at the same time post man tried and its giving response then what is wrong here.
I am not able to share the api url due to security reasons.
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'url_with_parameter',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Cookie: PHPSESSID=f1r22a2srpgamnidkflgqsuem2; csrf_token=c31d6332c0066fa652b79948c43e5dd7_d5ec9637ea9c6914f3cebeab7fa4ad4d',
'Host' => "localhost",
'User-Agent' => 'PostmanRuntime/7.31.0',
'Accept' => '*/*',
'Accept-Encoding' => 'gzip, deflate, br',
'Connection' => 'keep-alive'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
When 1020 error is returned by curl, it means typically that the request was blocked by security settings, which can include challenges like CAPTCHAs or browser checks.
Try to add UA header into your curl request, like
$headers = [
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
];
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $headers);

php script login to td ameritrade

I need to log into the TD Ameritrade website with my account. Note, I am not talking about the official API, I'm talking about their actual UI. I need to scrape from the site itself, unfortunately. I'm using curl in PHP, but any language you can get to work is probably fine. I've started with postman, which I'm usually able to get to work for this kind of thing, but it isn't returning anything when I copy the transactions from Chrome Dev Tools and importing into Postman. For example, it either loops back to the login site, or if I play with the settings it will flat out not return anything. The current issue with my php is that I get Maximum (10) redirects followed, it's an infinite loop where the login forwards back to itself. Unfortunately, for obvious reasons, I cannot post my username and password, so you would need an account to test. They are free, but not the easiest to set up. In any case, if you have any ideas that would be greatly appreciated.
<?php
header('Content-type: text/javascript');
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://auth.tdameritrade.com/oauth?client_id=MOBI%40AMER.OAUTHAP&response_type=code&redirect_uri=https%3A%2F%2Finvest.ameritrade.com%2Fgrid%2Fp%2Fsite&code_challenge=xNghkUhiiE_DSuVXLcSF1ufBVSPTQRa1ITybIyw2USc&code_challenge_method=S256',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HEADER => 1, // needed for getting cookies
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1",
CURLOPT_POSTFIELDS => 'su_username=' . $username . '&su_password=' . $password,
CURLOPT_VERBOSE => true,
CURLOPT_POST => true,
CURLOPT_AUTOREFERER => true,
// CURLOPT_HTTPHEADER => array(
// 'Content-Type: application/x-www-form-urlencoded'
// ),
));
//curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
// $cookie = dirname(__FILE__) . "/cookie.txt";
// curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);
// curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie);
$res = (object)array(
'response' => curl_exec($curl),
'info' => (object)curl_getinfo($curl),
'errors' => curl_error($curl)
);
print_r($res);

Get Request Working fine with Postman but not with PHP CURL

I have simple GET request on postman and it does working fine
https://www.instagram.com/p/CVhuRABqnAI/?__a=1&__d=dis
When Im using PHP CURL its did not respond me with Json data rather showing logo
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0",
CURLOPT_URL => "https://www.instagram.com/p/CVhuRABqnAI/?__a=1&__d=dis",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
if($error) {
echo "cURL Error:" . $error;
} else {
echo $response;
}
Can some one else me with this?
Finally I might know what to do as I just faced this problem.
Usually, there is just some kind of difference in between postman and curl. Or there is "something" else, because my solution was just to not send any headers at all...

curl request works from one server and give 403 on another

I am using curl to hit a url and get contents from it and below is the code
$url = 'http://uber.com';
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.16 (KHTML, like Gecko) \ Chrome/24.0.1304.0 Safari/537.16',
CURLOPT_CONNECTTIMEOUT => 180,
CURLOPT_TIMEOUT => 180 + 60,
CURLOPT_COOKIE => 'lang=en;'
));
$response = curl_exec($ch);
var_dump($response);
It gives me the content when I execute the script on local server but while executing this on staging and production server, situated in US, it give 403-forbidden error. I also tested the same from another server in US and it works fine.
Any help is appreciated.

PHP cURL login fails

There is a website http://www.tremorgames.com and I want to do a cURL login. I have a code which I use on my server http://shalva97.x10.mx/tremorlogin/ but it just does not work, but after a lot of testing I decided to install Apache on my PC and tested the exactly same code and it worked.
Here is the code :
<?php
$url="http://www.tremorgames.com/index.php";
$postdata = "loginuser=shalva&loginpassword=shalva&Submit=&saveme=1";
$ch = curl_init();
$f = fopen('request.txt', 'w');
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_VERBOSE => 1,
CURLOPT_STDERR => $f,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postdata,
CURLOPT_HEADER => 1,
CURLOPT_HTTPHEADER => array("Accept-Language: en-US;q=0.6,en;q=0.4", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Connection: keep-alive"),
CURLOPT_COOKIEFILE => "cookies.txt", //Save cookies
CURLOPT_COOKIEJAR => "cookies.txt", //Cookies located
CURLOPT_REFERER => 'http://www.tremorgames.com/index.php',
CURLOPT_ENCODING => 'gzip,deflate'
));
echo curl_exec($ch);
fclose($f);
curl_close($ch);
?>
Executing this same code on both my PC and server, I get different headers, on PC it receives multiple "Set-Cookie" header, but on server it is only one.
Why it does not work on the server? Why it works on my PC?
well after a lot of thinking i found out that it is not only headers is sent but the ip and my location. The site does not allow logins from other countries thats why it didnot loged in, the code is correct and it was all about server location. i hope this will help others who also try to do same thing.

Categories