I have an issue with the facebook linter feature. I'm trying to clean the Facebook cache of one my URL, with a PHP curl query. As you can see here (Updating Objects), Facebook got an api for scrapping all the content of an URL and update URL Facebook meta. It's the same API used in the Facebook Debugger Tool.
If I use their debugger manually, there is no problem. My URL is correctly scrapped and all corrects meta are retrieved. But it's not the case with a php curl query.
Here my actual code :
$furl = 'https://graph.facebook.com';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $furl );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POST, true );
$params = array(
'id' => "http://www.gametrader-app.com/aTPVev",
'scrape' => true,
);
$data = http_build_query( $params );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
$resultLinter = curl_exec( $ch );
The API result displays incorrect/old facebook meta.
Moreover, I have tried to call directly the URL of the Debugger without success
curl_setopt( $ch , CURLOPT_URL, "http://developers.facebook.com/tools/debug/og/object?q=http://www.example.com");
curl_setopt( $ch , CURLOPT_HEADER , 0 );
curl_setopt( $ch , CURLOPT_RETURNTRANSFER , true );
curl_setopt( $ch , CURLOPT_USERAGENT , $useragent );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$str_response = curl_exec( $ch );
I need to do this for one reason. Here the full process :
Publish a new ad on the iPhone App "GameTrader"
Post an open graph on facebook for this publish
That's all ;)
If I don't clean the URL cache on Facebook side before the post open graph, I get this error :
Error during open graph : OAuthException: (#3502) Object at URL
http://www.gametrader-app.com/aTPVev has og:type of 'website'. The property 'ad' requires an object of og:type 'gametrader-app:ad'
Can you help to understand what I'm doing wrong ?
Cheers!
Related
I am using get/post request to generate embed token of the powerbi report in php and i successfully generated the access token by following the example given in this link https://community.powerbi.com/t5/Developer/How-To-Get-embed-token-using-Get-Post-only/td-p/294475 but when i used this access token to generate embed token for me it returns empty array in response.This is my code
$headers = array(
"Authorization: Bearer <acesstoken generated>"
);
$url = 'https://api.powerbi.com/v1.0/myorg/groups/<group-id>/reports/<report-id>/GenerateToken';
$post_params = array(
'accessLevel' => 'View',
'datasetId'=>'<dataset-id>'
);
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_params);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
echo $response;
Any help would be appreciated thanks.
After the hardwork of 1 day I finally figured out i was using application id in the resource param for generating access token instead of this https://analysis.windows.net/powerbi/api link. So when i used this link ,the problem is solved and generated the embed token successfully.
I'm trying to follow this tutorial about REST API call of PODIO using CURL on my localhost.
I was able to get through on the step on getting the app authorized and I have now the authorization code on URL. But it seems I'm not getting response for access token I'm getting an error Undefined property: stdClass::$access_token using the code below. When I tried to do a print_r of variable $tokenresult to see those token response there's an error unexpected '$token_result' (T_VARIABLE). For advice you can give, thank you so much in advance!
<?php
$ch1 = curl_init('https://podio.com/oauth/token?grant_type=authorization_code&client_id=app_ID_i_got_on_PODIO_API key&redirect_uri=http://localhost/PODIO_API/podio-php/podiocurlrequest.php&client_secret=client_secret_key_i_got_fromPODIO_API_key &code=authorization_i_got_from_the_URL');
//curl_setopt($ch1, CURLOPT_TIMEOUT, 400);
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt( $ch1, CURLOPT_SSL_VERIFYPEER, 0 );
//curl_setopt($ch1, CURLOPT_POSTFIELDS, $data_array);
curl_setopt( $ch1, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch1, CURLOPT_RETURNTRANSFER, 1 );
$result1 = curl_exec($ch1);
curl_close($ch1);
$tokenresult = json_decode($result1);
$token = $tokenresult->access_token;
$token1 = "OAuth2 ".$token;
$headers = array(
"Authorization:".$token1
);
$podioch = curl_init('https://api.podio.com/item/app/my app id here/xlsx/&limit=500');
curl_setopt($podioch, CURLOPT_HTTPHEADER, $headers); //load all header data
curl_setopt($podioch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt( $podioch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $podioch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $podioch, CURLOPT_RETURNTRANSFER, 1 );
$resultdat = curl_exec($podioch);
curl_close($podioch);
?>
Have you thought about using Podio PHP client?
That should handle integration with Podio much nicely.
Please have a look at https://github.com/podio/podio-php and http://podio.github.io/podio-php/
visit below url for answer
https://stackoverflow.com/a/19149687/2240290
If you are on localhost then do this to resolve the issue.
I have and xml url from a supplier which generates xml content dynamically with php like;
http://www.example.com/outputxml/index.php?xml_service_id=161
This url is valid for a static ip so I gave him my websites hosting ip. Is there a way to open that url in browser with data scraping? Because My internet connection has no static ip.
Thank you.
I have tried below code;
$url = 'http://www.example.com/outputxml/index.php?xml_service_id=161?';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $xml );
$result = curl_exec($ch);
curl_close($ch);
echo $result;
But it gave html format.
Save the content on your server with something like a wget and then serve it. Please notice that you are probably going to infringe the policy of the xml's author (I don't know the consequences or the policy itself, but you should be careful), so you might consider to at least add a .htacces authentication on your server's page, just to not make the xml public.
I have a job application form that contains a bunch of text inputs and two fields to upload files (resume and cover letter).
This form needs to post to a job board API endpoint but the request has to be proxied so the API key isn't seen in the post. This is working fine with just the text inputs but I can't figure out how to get the files to upload as well. Below is what I have so far, which only posts the text.
How do I need to go about uploading the files as well?
<?php
if ( $_POST ) {
// API key
$api_key = 'super_secret_key';
$url = "https://api.myjobboard.io/applications/";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_USERPWD, $api_key . ":" . '' );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $_POST ) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
$response = curl_exec( $ch );
echo $response;
} else {
echo '<p>Error: No post data.</p>';
}
?>
I'm working with drupal 7 and REST api.
I'd like to log in into drupal with curl and later when i visit the website with a browser i want to be logged in.
i'm usin gthis code:
<?php
$user_data = array(
'username' => 'usertest',
'password' => 'pass',
);
$ch = curl_init();
$tmpfname = dirname(__FILE__).'/'.$_COOKIE['PHPSESSID'].'.txt';
curl_setopt($ch, CURLOPT_URL, "http://example.com/networklogin/user/login");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $user_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $tmpfname );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $tmpfname );
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
And it works pretty well, it logs the user in, but when i visit "example.com" i'm not logget in as "usertest".
Is there any way to log me into Drupal and allow me to access with a browser?
The goal is to log me in into many website with the same users when i log in into one as i wrote here (Same webserver, same drupal, same db, single sign on?).
Ok, i found a solution here:
Login to website through CURL and client browser
Use curl cookies for the user browser is pretty impossible..