i'm trying to display some custom facebook feeds on my website from a facebook fan page.
This is a summary sample of the php I used, and it works fine.
[...html code...]
// include the facebook sdk
require_once('resources/facebook-php-sdk-master/src/facebook.php');
// connect to app
$config = array();
$config['appId'] = 'MY_APP_ID';
$config['secret'] = 'MY_SECRET_CODE';
$config['fileUpload'] = false; // optional
// instantiate
$facebook = new Facebook($config);
// set page id
$pageid = "MY_PAGE_ID";
// access to the graph, starting with the feed
$pagefeed = $facebook->api("/" . $pageid . "/feed");
[...html code...]
$i = 0;
foreach($pagefeed['data'] as $post) {
// check if post type is a photo and catch the various part of the graph
if ($post['type'] == 'photo') {
//grab the thumbnail url in the graph
$picture_url = $post['picture'];
//get true sized photo by manipulating its url
$picture_url_big = str_replace("s130x130/","", $picture_url);
echo "<p><img class=\"img-icon\" src=\"" . $post['icon'] . "\"></p>";
echo "<h2 class=\"data-post\">" . date("j-n-Y", (strtotime($post['created_time']))) . "</h2>";
//displaying the photo
echo "<div class=\"img-thumb\"><img src=\"" . $picture_url_big . "\"></div>";
echo "<p class=\"manda-a-capo\"></p>";
if (empty($post['story']) === false) {
echo "<p>" . $post['story'] . "</p>";
} elseif (empty($post['message']) === false) {
echo "<p>" . $post['message'] . "</p>";
}
echo "<p><u><b>Vedi foto</b></u></p>";
echo "<p class=\"manda-a-capo\"></p>";
if ($post['shares']['count'] != "") {
echo "<p class=\"manda-a-capo share-num\">" . $post['shares']['count'] . " condivisioni.</p>";
}
}
$i++;
}
[...other code...]
The facebook graph contains only the thumb url of the photos, that is 130x130px. I discovered that some thumbs have an "/s130x130/" parameter in the url and, if you delete this parameter, you get the photo in its actual size.
So this explains this part of code (as above):
//grab the thumbnail url in the graph
$picture_url = $post['picture'];
//get true sized photo by manipulating its url
$picture_url_big = str_replace("s130x130/","", $picture_url);
//then displaying the photo
echo "<div class=\"img-thumb\"><img src=\"" . $picture_url_big . "\"></div>";
Unfortunately I noticed that not all photos from the page have this parameter and some of them have even a different url structure.
So the final result is that I can reach only few photos in their actual size, others remain a broken link.
Is there a way to manipulate the url to get all the photos in their own actual size?
Any advices?
Thanks.
P.S.
Here's the php to view the fb graph:
<?php
echo "<pre>";
print_r($pagefeed);
echo "</pre>";
?>
I found a temporary solution. In order to display the missing links I've added a php function that checks if the image url exist or not.
function checkRemoteFile($picture_url_big)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$picture_url_big);
// don't download content
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==FALSE)
{
return true;
}
else
{
return false;
}
}
And a control just above the "echo"
if (checkRemoteFile($picture_url_big)) {
//echo "image exist ";
$check = true;
$picture_url_big;
} else {
//echo "image does not exist ";
$check = false;
$picture_url_big = $picture_url;
}
Related
I have a script that gets and displays part of an external website.
https://pentiger.com/wycieczki.php
<?php
$config['base_url'] = 'www.ampolinc.com/';
$curl = curl_init('http://www.ampolinc.com/wycieczki.php');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$page = curl_exec($curl);
if(curl_errno($curl)) // check for execution errors
{
echo 'Scraper error: ' . curl_error($curl);
exit;
}
curl_close($curl);
$regex = '/<td width=\"694\" bgcolor=\"#FFFFFF\">(.*?)<table width=\"709\"
cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"margin:5px 0px 0px 167px;\">.<tr><td>/s';
if ( preg_match($regex, $page, $list) )
{
$list= str_replace('plan','print',$list);
<base href="http://ampolinc.com/">
echo "<font size = \"9\">";
echo $list[0]; //prints it to your page
echo "</font>";
}
else
print "Not found";
?>
but the images in Chrome do not display, when I click copy image url it copies fine.
I tried in Safari and images display. Any idea why? thanks.
How it looks in Chrome
How it looks on Safari
I'm trying to set up a live feed from a blog, but the contents are not displays. Any ideas? The blog is based in WP, I've set a contents curl below to a php file. The php file contains another curl to the physical blog feed.
<?php
try{
// Get RSS feed
$blog_feed = #file_get_contents_curl('http://www.coordsport.com/csblogfeed.php');
if ($blog_feed){
// Convert to traversable XML object
$blog_posts = new SimpleXMLElement($blog_feed);
// Set limits and counter
$list_count = 5;
$current_item = 0;
// Loop through each feed item
foreach ($blog_posts->channel->item as $blog_post)
{
// Increment counter and check count
if (++$current_item > $list_count) break;
// Force data type for description
$post_description = (string)$blog_post->description;
$desc_xml = new SimpleXMLElement('<div>' . $post_description . '</div>');
// Reset thumbnail
$thumbnail_src = '';
if (#$desc_xml->img[0])
{
$thumbnail_src = (string) $desc_xml->img[0]->attributes()->src;
}
}
else
{
echo 'Error Loading Feed';
}
}
catch(Exception $e)
{
echo 'Error Loading Feed.<br /><br /><div style="font-size:75%;color:#ccc;">' . htmlspecialchars($e) . '</div>';
}
?>
The file_get_contents_curl csblogfeed.php contains, the blog is working fine and displays correctly in the below URL.
<?php
echo file_get_contents('http://www.coordsport.com/blog/feed/');
?>
I am storing my files on Amazon Cloud Drive. And there are option for setting response-content-disposition to direct links from Amazon.
From the API:
response-content-disposition: (Optional) If specified, the content-disposition of the response will be set to this value
I need to set it download mp3 files. I don't need to play it on browser.
And I want to set downloaded file name: Эльбрус Джанмирзоев - Кавказская любовь.mp3
I tried many ways... Urlencode... Urlencode + http build query etc...
But now the result is: Эльбрус+Джанмирзоев+-+Кавказская+любовь.mp3 when downloading files.
And here is my php code:
<?php
function file_generate_download_link($filename = false, $force = true)
{
$json['tempLink'] = 'https://content-na.drive.amazonaws.com/cdproxy/templink/iTwUqoQ3cJXOpj6T8SCDmKwtF37TAENiSLQzy7pTSbkFfJttb';
$url = $json['tempLink'];
if($force)
{
$data['download'] = 'true';
}
if($filename)
{
$data['response-content-disposition'] = ' attachment; filename*=UTF-8\'\''.urlencode($filename).'';
}
if(isset($data)) {
$data = http_build_query($data);
$url .= '?' . $data;
}
return $url;
}
echo file_generate_download_link($filename = 'Эльбрус Джанмирзоев - Кавказская любовь.mp3');
?>
This code returns me this link:
https://content-na.drive.amazonaws.com/cdproxy/templink/iTwUqoQ3cJXOpj6T8SCDmKwtF37TAENiSLQzy7pTSbkFfJttb?download=true&response-content-disposition=+attachment%3B+filename%2A%3DUTF-8%27%27%25D0%25AD%25D0%25BB%25D1%258C%25D0%25B1%25D1%2580%25D1%2583%25D1%2581%2B%25D0%2594%25D0%25B6%25D0%25B0%25D0%25BD%25D0%25BC%25D0%25B8%25D1%2580%25D0%25B7%25D0%25BE%25D0%25B5%25D0%25B2%2B-%2B%25D0%259A%25D0%25B0%25D0%25B2%25D0%25BA%25D0%25B0%25D0%25B7%25D1%2581%25D0%25BA%25D0%25B0%25D1%258F%2B%25D0%25BB%25D1%258E%25D0%25B1%25D0%25BE%25D0%25B2%25D1%258C.mp3
If I enter this link Chrome saves this file with this name:
Эльбрус+Джанмирзоев+-+Кавказская+любовь.mp3
But I need excatly save file with this name:
Эльбрус Джанмирзоев - Кавказская любовь.mp3
Where is my mistake?
Gotcha! I need to use rawurlencode function!
So the right code is:
<?php
function file_generate_download_link($filename = false, $force = true)
{
$json['tempLink'] = 'https://content-na.drive.amazonaws.com/cdproxy/templink/iTwUqoQ3cJXOpj6T8SCDmKwtF37TAENiSLQzy7pTSbkFfJttb';
$url = $json['tempLink'];
if($force)
{
$data['download'] = 'true';
}
if($filename)
{
$data['response-content-disposition'] = ' attachment; filename*=UTF-8\'\''.rawurlencode($filename).'';
}
if(isset($data)) {
$data = http_build_query($data);
$url .= '?' . $data;
}
return $url;
}
echo file_generate_download_link($filename = 'Эльбрус Джанмирзоев - Кавказская любовь.mp3');
?>
Iv try to display BLOB-1B content or image in PHP, I have an app in Android that take an image then upload to my host mysql I have no problem with upload now its time to display in PHP, here is my code.
//config.php
public function _owners_img($stall_id){
$request ="SELECT `img` FROM `img_stall` WHERE `stall_id` = '$stall_id' LIMIT 1";
$result_query = $this->con->query($request);
while($data = $result_query->fetch_assoc()){
$result_data = $data['img'];
}
if (!empty($result_data)) {
return $result_data;
}else {
return false; }
}
//owner_img.php
include_once 'config.php';
$db = new database($con);
$db->dbconnect();
$owner = 3;
echo "<dt><strong>Stall Image:</strong></dt><dd>" .
'<img src="data:image/jpeg;base64,'.
base64_encode($db->_owners_img($owner)).
'" width="290" height="290">' . "</dd>";
but the problem is Am only getting small image icon or image not found. how do I fix this?
I'm trying to get a list of videos for a specific user with all the details for the video (title, desc., date, tags...)
I can get pretty much everything I need, but can't figure out how to get the upload date.
I tried using getVideoRecorded() and getRecorded(), but both return nothing.
I can't seem to find anything related to this on Google, all I can find is class references which tell me that I have to use getVideoRecorded or getRecorded, but nothing more.
Am I doing something wrong? how can I get the upload date?
Current code:
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient =
Zend_Gdata_ClientLogin::getHttpClient(
$username = $yt_username,
$password = $yt_password,
$service = 'youtube',
$client = null,
$source = '', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$yt = new Zend_Gdata_YouTube($httpClient);
$feed = $yt->getUserUploads($yt_username);
foreach($feed as $item)
{
echo "<div>";
echo "<h4>title: " . $item->getVideoTitle() . "</h4>";
echo "<p>id: " . $item->getVideoId() . " | ";
echo "upload date: " . $item->getVideoRecorded() . "</p>";
echo "<p>description: " . $item->getVideoDescription() . "</p>";
echo "<p>tags: " . implode(", ", $item->getVideoTags()) . "</p>";
echo "</div>";
echo "<hr>";
}
You can try and extract the < published > or < updated > tags from the following xml:
http://gdata.youtube.com/feeds/api/videos/{$videoId}