I'm trying to use the Facebook Linter programmatically, so that when I update a post it automatically pings FB to pull the new open graph information.
All the solutions I'm finding online don't seem to work anymore though, and are all old.
Is there a way to do this?
This is what I have so far which doesn't work
$params = array(
'id' => $url,
'scrape' => 'true',
'access_token' => '12345|987654321'
);
$ch = curl_init("https://graph.facebook.com?" . http_build_query($params));
curl_setopt_array($ch, array(
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
));
$result = curl_exec($ch);
Add CURLOPT_POST to your CURL request so that the data is POSTed to the Graph API:
curl_setopt_array($ch, array(
CURLOPT_HEADER => 0,
CURLOPT_POST => 1,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
));
See the documentation here.
Related
I am trying to get product data from google merchant center (google shopping ), my curl command works fine on postman, but not on php. Please help me
On postman:
On Php:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://shoppingcontent.googleapis.com/content/v2.1/436306321/products',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ya29.a0ARrdaM8TK4rZeVRnsj9MgcFg3STE1EqGvwj20J-REq8f6poCzGIv2MzUIegdSP1DDa_-HQpHIQNBTU6Rnxf7HsnWCjwkP7_pwkp-kr5zm0o0Z6EuZCVa4IdwHzX7MGM8SQ-94Vkxps4JRSbkgplYo4w1K8lPwQ'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
There's a free weather API in my country that I want to use to get rain data. The request is simple https://apitempo.inmet.gov.br/estacao/2021-05-03/2021-05-06/A826 and there's no authentication. If I try the request using Postman, my browser or AJAX, it works fine and I get the results I need. However, using cURL, I get nothing.
Here's the PHP code that I tried:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://apitempo.inmet.gov.br/estacao/2021-05-03/2021-05-06/A826',
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);
curl_close($curl);
echo $response;
I have the cURL.dll installed and tested in another server, but it didn't work.
Is there a problem with the code or is it the API that blocks PHP requests?
its look like this website looking for user-agent header.
try this:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://apitempo.inmet.gov.br/estacao/2021-05-03/2021-05-06/A826',
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(
'User-Agent: something'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
I've been stumped on why my PHP cURL request is not properly signing me in to a login website (for non-personal reasons I won't disclose which one).
This is my code:
$user = "TestUsername";
$pass = "TestPassword";
$curl = curl_init();
$curl_config = array(
CURLOPT_URL => "http://website_name.com/form_action_url",
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => array('user' => urlencode($user),
'pass' => urlencode($pass)
),
CURLOPT_HEADER => true,
);
curl_setopt_array($curl, $curl_config);
$response= curl_exec($curl);
Can anyone figure out what I'm doing wrong? Thanks in advance.
Is there any solution to working imap via proxy on php ? Will be great if I can use fsockopen and work with imap via proxy. How to connect to imap via proxy? How to log in, send commands ? I have looked all web and did not found any solution. There really absent enough information for this topic. Great thank in advance for anybody who can help!
$ch = curl_init("imaps://imap.server.com:993/INBOX;UID=1");
curl_setopt_array($ch,[
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_USERNAME => 'postbox#server.com',
CURLOPT_PASSWORD => 'password',
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
CURLOPT_PROXY => "proxy-ip-addr:proxy-port"
]);
$content = curl_exec( $ch );
curl_close($ch);
echo $content;
This is example how to get message #1 form Inbox.
Non-GET IMAP commands can be sent with CURLOPT_CUSTOMREQUEST option.
For example, to delete message:
$ch = curl_init("imaps://imap.server.com:993/INBOX;UID=1");
curl_setopt_array($ch,[
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_USERNAME => 'postbox#server.com',
CURLOPT_PASSWORD => 'password',
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
CURLOPT_PROXY => "proxy-ip-addr:proxy-port"
]);
$content = curl_exec( $ch );
curl_close($ch);
I am Trying to convert an existing phpCurl request to latest guzzle and not getting anywhere fast.
This is the current request.
$curl_opts = array(
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => array('Content-Type: text/json', 'Content-length: '.strlen($json)),
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $json,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => 'https://the-domainservice.php',
CURLOPT_VERBOSE => false,
CURLOPT_SSLCERT => '/path/to/file.pem',
CURLOPT_SSLCERTTYPE => 'pem',
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1
);
$curl = curl_init();
curl_setopt_array($curl, $curl_opts);
$response = curl_exec($curl);
For Guzzle I have tried so many ways but here are a couple of example.
$response = $this->client->post('https://the-domainservice.php', [
'body' => $postData,
'cert' => '/path/to/file.pem',
'config' => [
'curl' => [
CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true
]
]
]
);
And more verbose of
$request = $this->client->createRequest('POST', 'https://the-domainservice.php', [
'cert' => '/path/to/file.pem',
'verify' => false,
'headers' => [
'Content-Type' => 'text/json',
'Content-length' => strlen(json_encode($postData))
]
]);
$postBody = $request->getBody();
foreach ($postData as $key => $value) {
$postBody->setField($key, $value);
}
$response = $this->client->send($request);
For my guzzle requests I am just getting
GuzzleHttp\Exception\ServerException: Server error response [url] https://the-domainservice.php [status code] 500 [reason phrase] Internal Service Error
Really hope someone can advise.
Feel a little stupid now.
Just needed to send json data and all worked, end result was.
$response = $this->client->post('https://the-domainservice.php', [
'body' => json_encode($postData),
'cert' => '/path/to/file.pem',
]
);
Excellent stuff Guzzle !