I am getting the following response from the Facebook Ad Library API
{"error":{"message":"(#803) Some of the aliases you requested do not exist: \u003CAPI_VERSION>","type":"OAuthException","code":803,"fbtrace_id":"AXZ00I_mwgTvJwqIImb1SBw"}}
Below is the CURL I am trying to execute;
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/<API_VERSION>/ads_archive');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "search_terms='california'&ad_type=POLITICAL_AND_ISSUE_ADS&ad_reached_countries=['US']&access_token=330479468051422|t_w8UDcd2QYqQ_hfxfs-LsKSxIA");
$headers = array();
$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);
echo $result;
?>
Is there anything you can see that I have done wrong, much apprecaited thankyou.
Related
In PS I made this:
$body=#{
'code'='$code'
'access_token'=$token
}
$result = Invoke-RestMethod -Uri $uri -Method Post -Body $body
Works perfect. How can I do the same in PHP Curl ?
Ive tryed something like this:
$data = array("code" => $code, "access_token" => $token);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
"code=" . $code,
"access_token=" . $token
));
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('ContentType:text/plain'));
$result=curl_exec ($ch);
print_r($result);
But I keep getting error like : Parameter token is missing.
To upload objects to google cloud storage buckets, I need an authentication token. I have chosen JSON API method to upload objects to buckets.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/upload/storage/v1/b/Mybucket/o?uploadType=media");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "yourdata");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$headers = array();
$headers[] = "Authorization:Bearer <TOKEN>";
$headers[] = "x-goog-project-id: xxxxxxxxxxx";
$headers[] = "x-goog-user-project: xxxxxxxxxxx";
$headers[] = "Content-Length: 8";
$headers[] = "Content-Type: image/jpeg";
$headers[] = "x-goog-acl: public-read-write";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>
Is there any way to upload object without these type of
authentication or any other authentication method?
How to generate this token (bearer) programmatically using api/curl/php?
function getOAuthToken(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$headers = array();
$headers[] = "Metadata-Flavor: Google";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
// echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
$result = json_decode($result,true);
return $result['access_token'];
}
$result['access_token'] is the bearer token.
here is my script of php to call remote restful api, the username password are hard coded in source code,
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost/m1/m1apiserver/public/api/login");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"email=elson%40bla.com&password=bla");
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec ($ch);
curl_close ($ch);
$j = json_decode($json);
// further processing ....
if ($j->token) {
//echo $j->token;
$output = file_get_contents("http://localhost/m1/m1apiserver/public/api/product?token=".$j->token);
echo $output;
}
but are there any techniques to secure the username password?
Instead of adding the following Header information it is showing HTML tag in PHP Mail.
$headers = "From: ".$name."<".$email.">\r\n";
$headers .= "Reply To: ".$email."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
Please help me.
Try this,
$subject = 'Mail Subject';
$message = 'Test';
$headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= "X-Mailer: PHP \r\n";
$headers .= 'From: ".$name."<".$email.">' . "\r\n";
$headers .= 'Reply-To: ".$email."' . "\r\n";
mail($to, $subject, $message, $headers);
Example from my mail()
$header = "From: Backapp.ru <noreply#backapp.ru>\r\nContent-type: text/html; charset=utf-8";
The basic usage of mail() function with headers is:
<?php
$to = "you#local.com";
$subject = "My email test.";
$message = "Hello";
$headers = "From: myplace#local.com\r\n";
$headers .= "Reply-To: myplace2#local.com\r\n";
$headers .= "Return-Path: myplace#local.com\r\n";
$headers .= "CC: sombodyelse#local.com\r\n";
$headers .= "BCC: hidden#special.com\r\n";
if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>
You don't send us your output so we don't know wheres the problem.
Here is the original code I had in my PHP script:
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
I got an email from Paypal saying that I needed to upgrade my IPN script so that it uses HTTP/1.1. So here is what I changed my code to, based on their directions:
$header .="POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .="Content-Type: application/x-www-form-urlencoded\r\n";
$header .="Host: www.paypal.com\r\n";
$header .="Connection: close\r\n";
Payments have gone through today, but the IPN is no longer updating my database and this is the only change I made to it. Any ideas on what to do?
Thanks!
Yes. I have just done battle with this. What worked for me was to remove the connection close header, and add a trim to the response back from PP. Here are the headers:
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
Here is the fsockopen:
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
and here is the trim on the response back from PP:
if (!$fp) {
// HTTP ERROR
error_mail("Could not open socket");
//
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = trim(fgets ($fp, 1024));
}
//
// check the payment_status is Completed
// check that receiver_email is your Primary PayPal email
//
if ((strcmp ($res, "VERIFIED") == 0) && ($payment_status == "Completed") && ($receiver_email == $valid_receiver_email)) {
That worked for me.