I am new in web development sector. It's seem to impossible to fetch my web pages using facebook Open Graph Object Debugger manually. When I search code to force re-scrape I found this code, but confused where to add. I thought it is php function and include , but it print parse error. Is it complete code ?, am I right ? Many website and blog advice to use following code. But I have no idea. I can't find clear way.
<?php $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>
<?php curl "http://developers.facebook.com/tools/debug/og/object?q=$url"; ?>
This is what I'm using
private function updateFacebookScrape($url){
$ch = curl_init("http://developers.facebook.com/tools/debug/og/object?q=".$url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
}
Also, make sure curl is installed on the server.
Related
I want to generate google drive direct download link without opening web page.
I have found 1 site which do same thing but I did not find how he is doing.
below is the site which generates direct download link without opening google drive page.
https://links-safety.com/download.php?id=0B475ByfcR9n4a1JMVEZxQno2Tmc
0B475ByfcR9n4a1JMVEZxQno2Tmc is google file and replace with any file.
can anyone tell me how can I do that?I want to make same page like above site.
I tried this url but its not working. instead of starting download it opens page.
https://drive.google.com/uc?id=0BwSYfbOPSw89Rno4LTZpSGF6RUE
A quick look at the source of the site, it generates the following javascript.
<script>
setTimeout(function() {
window.location.href = "https://doc-0o-a0-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/nemv3kbhggb02fn2933p80ec5vsi521t/1512345600000/10410701494873540224/*/0B475ByfcR9n4a1JMVEZxQno2Tmc?e=download";
}, 300);
</script>
But where does that url come from?
With a little fiddling and watching the console on when it does ask to confirm on google, you can see it does a POST request and returns some json.
)]}'
{"disposition":"SCAN_CLEAN","downloadUrl":"https://doc-0c-9k-docs.googleusercontent.com/docs/securesc/aonp7ed1gjmns5tl5di4fl0psa1cppk8/16panrhf9etu7sqgddkaduij5anokf8t/1512345600000/17294955007197410767/17294955007197410767/0ByzJffaEk18uN2ZLeGlIRGVOaDJmWS1WU1RUN3dXUGdtUUx3?e\u003ddownload","fileName":"install.sh","scanResult":"OK","sizeBytes":4936}
So just mock that with PHP
Make a json POST request to that url, google will respond with the json, then just strip out )]}' json decode it, then use a header to redirect to the file.
<?php
$id = '0B475ByfcR9n4a1JMVEZxQno2Tmc';
$ch = curl_init('https://drive.google.com/uc?id='.$id.'&export=download');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, []);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
... see notice below
));
$result = curl_exec($ch);
$object = json_decode(str_replace(')]}\'', '', $result));
exit(header('Location: '. $object->downloadUrl));
Edit (08-04-18)
Looks like some additional headers have been added, if missing it will throw a 400 Bad Request. No biggie, it's still easy to mock it by looking at the request headers when downloading a file from your own drive. I'm unwilling to share a copy&paste solution, as the above still works you just need to add some headers and StackOverflow is not a free coding service nor am I required to maintain every answer I've ever written. Good luck.
I am working in a web application that was coded using procedural PHP. No framework, no MVC, no OOP. It is what it is. At this point in time, recoding to use some sort of framework is not feasible. To my benefit, it is very well organized, and so it's easy to work within. Anyway - they want to add on a Point of Sales system, and have landed on Kounta (kounta.com). Kounta has an API that is RESTful and returns JSON or XML.
I am absolutely brand new to writing applications that integrate with API's, and there are a lot of terms being slung around that I am not quite familiar with.
From my understanding, I need to authenticate myself using oAuth 2.0, and from there, can make server calls to pull data from their server.
The first piece of that is what I need help with.
I have my client ID and client secret. I am just not sure what to do with them, and how to pass them to their server via script in order to receive a token, so that I can then make those server calls.
The Kounta API Documentation can be found here (http://www.kounta.com/documentation/).
Any help that anybody could provide would be greatly appreciated. At this point, I am not sure where to even get started.
Here is the code that I am currently using. This code returns an error asking me to identify myself to Kounta.
<?php
$url = "https://api.kounta.com/v1/companies/5678/orders.json?created_gte=2013‑06‑01";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 4);
$json = curl_exec($ch);
if(!$json) {
echo curl_error($ch);
}
curl_close($ch);
print_r(json_decode($json));
?>
I'm not too familiar with Kounta, but I recently did a project which required me to fetch data from Instagram based on a users ID.
To do this, I used CURL. Instagram has a pretty open API and even some examples. So it wasn't too hard for me to figure it out.
See below for my example:
<?php
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$result = fetchData("https://api.instagram.com/v1/users/<user>/media/recent/?access_token=<access_token>&count=4");
$result = json_decode($result);
foreach ($result->data as $post) {
echo '<div class="col-sm-3">
<a href="'.$post->images->standard_resolution->url.'" data-lightbox="instagram" data-title="'.$post->caption->text.' '.implode(' #',$post->tags).'">
<img src="'.$post->images->thumbnail->url.'" alt="" /></a>
</div>';
}
?>
What this does is simply connect to Instagrams API with a user ID and access token inside the URL and returns a JSON Array.
My only purpose for showing you this is because this might be exactly what you will need to do going forward with Kounta, in some form or fashion. I have not reviewed their API or anything so I can't say for sure. However, I'm more than certain CURL will be your best bet.
I would advise you to fully read through their API once more and see what options they have or maybe even see if they offer any examples to help you get started.
EDIT: You mentioned they they return JSON and XML. This is good to know because that more than likely means you can use CURL to get data from their databases.
Let me know if you have any questions.
We would like to integrate Skydrive in our website, like we're currently doing with Google Drive but I'm lost in how to retrieve the root folders and files.
I've read these posts and docs:
Access SkyDrive using PHP and OAuth
Convert to PHP REST CURL POST
Skydrive API here: http://msdn.microsoft.com/en-us/library/live/
Curl doc on http://php.net - even if I'm still confused about that
And yet, I can't seem to get what I wanted.
I've already the access_token and it's correctly assigned, the scopes are also correct (I'm using wl.contacts_skydrive), so, I'm putting here part of the code I've so far so you can tell me what I'm missing, what I should add or if I'm taking a wrong turn.
//$token is correctly assigned
$url = 'GET https://apis.live.net/v5.0/me/skydrive/files?access_token='.$token;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
Thanks you for your time taken to help me.
You need to use CURLOPT_RETURNTRANSFER to return the transfer as a string.
Otherwise you will get true or false. Assuming you were getting true from curl_exec
Try adding
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
I am trying to access some basic info from an XML based API. I'm new to this and am getting lost reading the guides on php.net and via google that seem to assume I already know the basics.
The input needs to be formatted as follows:
<query>
<auth_key>xxxxx</auth_key>
<command>get_account</command>
<account_id>11122</account_id>
</query>
The return will be in an XML format. I assume I need to use CURL to connect and send the input, but I'm lost - how should the PHP code look to do this?
::UPDATE::
okay, I'm still struggling and not making any progress. I've found a tutorial that has kinda lead me to the following code, but it's not doing anything and I can't figure out how/where I'm supposed to acutally send the XML data through to the url.
$URL = 'http://www.test.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
print_r($data);
I'm not getting this right and not sure what I'm supposed to be doing. Any help would be appreciated!
The API probably expects you to POST your request to the server, in which case an HTTP POST with cURL example should help. Check the HTTP code of server response (200 is good, others are probably bad) - and if it's good then parse the XML.
Most APIs have very good documentation and examples though. It's worth reading through them or Googling for other people in your shoes.
I ended up stumbling on the following link: http://www.phpmind.com/blog/2009/08/how-to-post-xml-using-curl/
From there I got the sample code working and manipulated it to suit my needs. I also ended up using http://php.net/manual/en/book.simplexml.php for the xml parsing and it seemed very straight forward.
I am using PHP to find whether image urls are active or broken. I have been using the following code which I found in one of the answers on stackoverflow itself.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200)
{
echo "image exists<br/>";
}
curl_close($ch);
If I use a normal image URL then the program is working fine, but if the image link is present in a blog like this (http://unspokenstyle.files.wordpress.com/2009/01/yorkegrammy.jpg) or if the content management is done using wordpress like this (http://rockandroll.blog.br/wp-content/uploads/2009/01/radiohead-na-rollingstone3.jpg), then I am getting a "400 Bad Request" error.
Am I missing something in the code?
Please help.
P.S.: I cannot use certain PHP functions like PHP getimagesize as I am using third party hosting. So I have to use CUrl.
I tested your function and on my rig it's working just fine. So it's not your code. Is it possible they blocked your IP? Does the function work when you fetch a image from your own server (with http://)?
On your host can you use the PHP function: file_get_contents($url)?