Facebook PHP Api suddenly not working - php

<?php
//get token
$access_token = $facebook->getAccessToken();
$albumCover = $facebook->api("/". $album_id ."?fields=picture", "get");
//echo $albumCover['picture']['data']['url'];
//echo '<pre>';
//print_r($albumCover);
//echo '</pre>';
?>
<div class="fb-album<?php if ($counter % 5 == 0){echo ' no-right';}; ?>">
<a href="<?php the_permalink(); ?>">
<div style="width:160px; height:100px; overflow:hidden;">
<img width="160px" src="<?php echo $albumCover['picture']['data']['url']; ?>" />
</div>
</a>
<p><?php the_title() ?></p>
</div>
All of a sudden this doesnt work, and returns no error, could someone shed some light on this for me?
Thanks
UPDATE:
Found the answer, looks like I could not access the cover photo of each album with ?fields=picture anymore, I had to use ?fields=cover_photo and dig into that array, heres my solution, thanks for all your help STACK
<?php
//get token
$access_token = $facebook->getAccessToken();
$albumCover = $facebook->api("/". $album_id ."?fields=cover_photo", "get");
//echo $albumCover['picture']['data']['url'];
$albumCover2 = $facebook->api("/". $albumCover['cover_photo'] ."?fields=picture", "get");
//echo '<pre>';
//print_r($albumCover2);
//echo '</pre>';
?>
<div class="fb-album<?php if ($counter % 5 == 0){echo ' no-right';}; ?>">
<a href="<?php the_permalink(); ?>">
<div style="width:160px; height:100px; overflow:hidden;">
<img width="160px" src="<?php echo $albumCover2['picture']; ?>" />
</div>
</a>
<p><?php the_title() ?></p>
</div>
I appologize for the formatting, its quite hard to make it look right in this editor

Whenever Facebook API does not get data or does not work,
it logs error in PHP's error log. Check your PHP error log.

There was a breaking changes release today; it's worth checking out the release notes to see how you might have been affected. At a guess, something to do with the privacy changes...

You also need to use setAccessToken method after getAccessToken.
$access_token = $facebook->getAccessToken();
$facebook->setAccessToken($access_token);

As per the error message your have posted in the comment,
If the index active does not exist then you get notice error mod_fcgid. To avoid that you can do check if that index is set / exists.
Code:
if($blah['active']=="something"){foo();}
Should be:
Code:
if(isset($blah['active']) && $blah['active']=="something"){foo();}

Related

Session variables not working correctly

In my code i use a for each and for some reason it takes for ever to load and it screws up half way through with not displaying the name or it just does show up.
Code, http://hastebin.com/axutiqaqev.php (Not displaying correctly here)
<?php
$griditems = json_decode(file_get_contents($url));
foreach ($griditems->rgInventory as $index=>$items) {
$_SESSION['itemdesc'] = json_decode(file_get_contents($url));
$_SESSION['itemnamevalue'] = strval($items->classid) . "_" . strval($items->instanceid);
$_SESSION['itemname'] = $_SESSION['itemdesc']->rgDescriptions->$_SESSION['itemnamevalue']->market_name;
//echo $index; // will get index
?>
<div class="col-lg-2 col-sm-3 col-xs-4">
<a href="#">
<p><a class="hovertext" href="#" title="<?php echo $_SESSION['itemname']; ?>"><img src="https://steamcommunity-a.akamaihd.net/economy/image/class/730/<?= $items->classid ?>/150fx125f" class="thumbnail img-responsive"></a></p>
</a>
</div>
<?php
}
session_unset();
?>
Website: csgohighroller.com
Everything is working fine but it stops working after i use it once and when a player has too many items.
Example inventory http://www.csgohighroller.com/backpack.php?id=baconcraze

PHP Code is printing text not typed code

I have created a homepage editor tool in a script I purchased. The function of this homepage editor is to allow me to create different sections and display them one on top of the other in the order they are created. Which in hopes will give me an effect of several blocks that stretch width of the screen.
All seems to work well except one piece. I input my html and php code into the field in the admin panel and it saves to the db as I wrote it. However, when I go to echo each section back to the homepage it just displays my php code as plain text and doesn't interpret it as php and do its function.
Here is code from the homepage.php that prints the results.
<?php
session_start();
require_once("inc/config.inc.php");
if (isset($_GET['ref']) && is_numeric($_GET['ref']))
{
$ref_id = (int)$_GET['ref'];
setReferal($ref_id);
header("Location: index.php");
exit();
}
/////////////// Page config ///////////////
function get_all_section($section_id='')
{
$sql="SELECT * FROM `cashbackengine_homepage` WHERE 1";
if($section_id!="")
{
$sql.=" AND section_id='".$section_id."'";
}
$sql.=" AND section_status=1";
$sql.=" ORDER BY section_order ASC";
//echo $sql;
$res=mysql_query($sql);
while($row=mysql_fetch_array($res))
{
$section_array[]=array(
'section_id' =>$row['section_id'],
'section_name' =>$row['section_name'],
'section_desc' =>$row['section_desc'],
'section_order' =>$row['section_order'],
'section_status' =>$row['section_status'],
'last_updated' =>$row['last_updated'],
);
}
return $section_array;
}
$get_all_section=get_all_section('');
/*$get_all_section2=get_all_section('2');
$get_all_section3=get_all_section('3');
$get_all_section4=get_all_section('4');
$get_all_section5=get_all_section('5');*/
for($i=0; $i<count($get_all_section);$i++)
{
//echo htmlspecialchars_decode($get_all_section[$i]['section_desc']);
//echo htmlspecialchars_decode(stripslashes(str_replace(" ","",(str_replace("<br />","\n",$get_all_section[$i]['section_desc'])))));
echo $get_all_section[$i]['section_desc'];
}
?>
I am certain the problem has to do with the echo at the end. But I am unsure how to use htmlspecialchars to make it work with php if it even will. Or if I have to put something weird in my saved section.
Here is one of my sections. Any help is greatly appreciated. Thank you.
<div style="height:260px; width:100%; background-color:#000; margin:0px; color:white;">
<div id="header">
<div id="logo"><img src="<?php echo SITE_URL; ?>images/logo.png" alt="<?php echo SITE_TITLE; ?>" title="<?php echo SITE_TITLE; ?>" border="0" /></div>
<div class="start_saving">
<div id="links">
<?php if (MULTILINGUAL == 1 && count($languages) > 0) { ?>
<div id="languages">
<?php foreach ($languages AS $language_code => $language) { ?>
<img src="<?php echo SITE_URL; ?>images/flags/<?php echo $language_code; ?>.png" alt="<?php echo $language; ?>" border="0" />
<?php } ?>
</div>
<?php } ?>
<div id="welcome">
<?php if (isLoggedIn()) { ?>
<?php echo CBE_WELCOME; ?>, <span class="member"><?php echo $_SESSION['FirstName']; ?></span><!-- | <?php echo CBE_ACCOUNT ?>--> | <?php echo CBE_BALANCE; ?>: <span class="mbalance"><?php echo GetUserBalance($_SESSION['userid']); ?></span> | <?php echo CBE_REFERRALS; ?>: <span class="referrals"><?php echo GetReferralsTotal($_SESSION['userid']); ?></span>
<?php }else{ ?>
<a class="signup" href="<?php echo SITE_URL; ?>signup.php"><?php echo CBE_SIGNUP; ?></a> <a class="login" href="<?php echo SITE_URL; ?>login.php"><?php echo CBE_LOGIN; ?></a>
<?php } ?>
</div>
</div></div>
</div>
It looks like you're getting these section contents pieces out of your database, and not from a file stored on your web server. Is that correct?
Assuming that's true, then my next question would be, who populates this data? Is this taken in any way from user input? The reason why I ask is because of my next suggestion, which may or may not be received well.
The reason why your PHP code isn't executing, is because it's being retrieved from the database and output as a string, not as code. So how do you execute code that's stored in a string, you ask? Well, the answer to that question is to use eval() on the string. But this is where you have to be really careful!!!!!!! If any part of that string could have possibly come from an untrusted source, then malicious PHP code could be executed, which could potentially give evildoers a way into your server, where they can find all the information in your database, server, etc. Make sure you know where your code is coming from before executing it!
You make a good point that it's HTML mixed with PHP. So I see two possible solutions...
This post suggests that you could do eval(' ?>'. $section .' <?php'); This makes sense, you're breaking out of PHP before you eval your string, and so requiring the included string to open its own PHP tags to write PHP code.
Another way I can think of would be to throw the contents into a temporary file, and then include() that file:
// get contents, store in $contents
$filename = tempnam(sys_get_temp_dir(), 'section');
file_put_contents($filename, $section);
include($filename);
unlink($filename);

Facebook feeds on website

I'm trying to get some fb feeds on a website. I've searched the web and found a couple things I could try. After failing quite a bit, I've managed to get it. Today the access token wasn't valid anymore, so I got a new one and it worked again. After a bit (token still valid) it didn't anymore (got two messages). So I searched again and found a new solution that works and I think that gives me a token which is longer valid. This is the php code:
<?php
$limit = 3;
$profile_id = "32796xxxxx64243";
//App Info, needed for Auth
$app_id = "59351xxxxx41974";
$app_secret = "082d36fe4108ae51xxxxxxxxxxfb84b4";
//retrieve a new Auth token
$curl = 'https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id='.$app_id.'&client_secret='.$app_secret;
//$authToken = file_get_contents($curl);
$authToken = file_get_contents("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={$app_id}&client_secret={$app_secret}");
$data = file_get_contents("https://graph.facebook.com/{$profile_id}/feed?{$authToken}");
echo $data;
?>
This gives me following result:
Now I'm trying to get all the info out of it, but here is where I'm getting an error in my foreach loop. This is the code I use:
<div id="footer">
<h5>Laatste Facebook feeds</h5>
<div class="wrapperfb">
<?
$counter = 0;
foreach($data->data as $d){
if($counter==$limit)
break;
?>
<div class="singlefb">
<div class="imgfb">
<a class="afb" href="http://facebook.com/profile.php?id=<?=$d->from->id?>">
<img border="0" alt="<?=$d->from->name?>" src="https://graph.facebook.com/<?=$d->from->id?>/picture"/>
</a>
</div>
<div class="textfb">
<span style="font-weight:bold"><a class="afb" href="http://facebook.com/profile.php?id=<?=$d->from->id?>">
<?=$d->from->name?></a></span><br/>
<span style="color: #999999;">on <?=date('F j, Y H:i',strtotime($d->created_time))?></span>
<br/>
<?=$d->message?>
</div>
</div>
<?
$counter++;
}
?>
</div>
</div>
This is the error I'm getting:
Warning: Invalid argument supplied for foreach() in
/customers/9/2/3/beach-korfbal.be/httpd.www/facebookFeeds.php on line
19
line 19 is the foreach loop:
foreach($data->data as $d){
It's probably something stupid I'm looking over. Could someone please help me out. This is the last thing I need to complete to launch the site.
It works now thanks to Abhik Chakraborty's comment.
This is the full code:
<?php
$limit = 5;
$profile_id = "32796xxxxx64243";
//App Info, needed for Auth
$app_id = "59351xxxxx41974";
$app_secret = "082d36fe4108ae51xxxxxxxxxxfb84b4";
//retrieve a new Auth token
$authToken = file_get_contents("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={$app_id}&client_secret={$app_secret}");
$data = json_decode(file_get_contents("https://graph.facebook.com/{$profile_id}/feed?{$authToken}"));
?>
<div id="footer">
<h5>Laatste Facebook feeds</h5>
<div class="wrapperfb">
<?
$counter = 0;
foreach($data->data as $d){
if($counter==$limit)
break;
?>
<div class="singlefb">
<div class="imgfb">
<a class="afb" href="http://facebook.com/profile.php?id=<?=$d->from->id?>">
<img border="0" alt="<?=$d->from->name?>" src="https://graph.facebook.com/<?=$d->from->id?>/picture"/>
</a>
</div>
<div class="textfb">
<span style="font-weight:bold"><a class="afb" href="http://facebook.com/profile.php?id=<?=$d->from->id?>">
<?=$d->from->name?></a></span><br/>
<span style="color: #999999;">on <?=date('F j, Y H:i',strtotime($d->created_time))?></span>
<br/>
<?=$d->message?>
</div>
</div>
<?
$counter++;
}
?>
</div>
</div>

javascript based slideshow not working

I'm trying to implement a simple javascript/jquery-1.6.2 slideshow (I'm not used to javascript), the problem I have is that the items are all shown and I don't know how to hide them.
here is my PHP/HTML code:
<?php
$c = 0;
// show parts of latest news:
foreach ($items AS $data) {
// news image
$image = './images/'.$data['image'];
// description
$part_description = substr(nl2br($data['content']), 0, 120);
?>
<div id="cap_<?php echo $c; ?>" class="cap" >
<h3><a href="<?php echo WEBSITE.'/news/view?id='.$data['id']; ?>" >
<?php echo $data['title']; ?></a></h3>
<table>
<tr>
<td>
<a href="<?php echo WEBSITE.'/news/view?id='.$data['id']; ?>" >
<img alt="Item image" width="200"
src="<?php echo $image; ?>" />
</a>
</td>
<td>
<strong>By</strong>
<?php echo $data['author']; ?>
<br/>
</td>
<tr/>
</table>
<p>
<?php echo stripslashes($part_description); ?>
<a href="<?php echo WEBSITE.'/news/view?id='.$data['id']; ?>" >
read more
</a>
</p>
</div>
<?php
$c++;
}
// show links:
?>
<div class="links">
<?php
for ($i=0; $i<$k; $i++) {
?>
<a href="javascript:slideShow(<?php echo $i; ?>, <?php echo $k; ?>);" class="link_number" id="link_<?php echo $i; ?>">
<?php echo $i+1; ?>
</a>
<?php
}
?>
And my js function:
function slideShow(id, max) {
var inputHide = null;
for (var i=0; i<max; i++) {
$('#cap_'+id).fadeOut(500);
inputHide = document.getElementById('cap_'+i);
document.getElementById('link_'+i).style.backgroundColor = '#999999';
}
$('#cap_'+id).fadeIn(500);
document.getElementById('link_'+id).style.backgroundColor = 'black';
}
I have two questions:
Q1: how can I fix this problem and show only one
Q2: is it better if I use a ready-to-use script like jqueryui?
In terms of your second question, It depends on what you need, and your understanding of JS. If you have a pure JS script, and you understand how and why it works, you can tailor it to your needs more. 'personalise it', if you like. However if your knowledge of JS is limited, then a ready to use script may suit you better.
A good way to learn things is to find a pure JS script somewhere (probably many on here), and use that one, but do your research and use your initiative until you understand how it works. Then you can use it in other projects, change it, use bits of it. That's how I learnt most of my javascript!
I've had some trouble with slideshows recently too, good luck! :)
Q1: this should work: inputHide.style.display = 'none';
Q2: In my opinion, both ways are good

Permanent changes with "onclick" handler?

I'm attempting to modify an app for facebook that uses php and javascript.
It allows a user to send gifts to each other's wall. When a gift is received, it show's on the app's notification page for that user.
The problem: after a gift is accepted, it still shows on the notifications page. I suppose because it was deemed necessary in order for the point system as well as the history functions to operate properly. It appears that gifts older than 30 days are no longer displayed. I tried to permanently change the date of the gift after it's accepted.
Can anyone please suggest possible ways to:
Option 1. After the gift is accepted, permanently change it to a different image to inform the user "you have already accepted this". Without removing it from the database.
Option 2. Remove the gift from the page (or prevent it from being displayed) after it's accepted...without deleting it from the database. .hide and display:none; are not viable options because the gift will be displayed again...every time the page loads.
Option 3. Last and least desired option, remove the gift from the page and database as well.
The original code for that page is below. The part of the code that I'm guessing needs to be modified is located between the asterisk dividers. I hope it's not too difficult to follow :-/
Thanks for your time.
<?php
if(!isset($facebook))
{
$user_id=$_POST['user_id'];
}
else
{
$user_id=$user_info['UserID'];
}
$news_limit=$current_time-2592000;
$history_query=mysql_query("SELECT * FROM ".$exchange_table." WHERE Time>'$news_limit'
AND ReceiverID='$user_id' ORDER BY Time DESC");
$history_num=mysql_num_rows($history_query); ?>
<div style="font-size:14px;width:720px;padding:10px;<?php echo $background_one; ?>"
align="left">
<div style="font-weight:bold;font-size:16px;color:#6f6f6f;">
<?php echo $nav_info['home']; ?>
</div>
<div style="width:100%;margin-top:10px;" align="center">
<img src="<?php echo $app_info['image_url']; ?>divider.gif">
<img src="<?php echo $app_info['image_url']; ?>divider.gif">
<img src="<?php echo $app_info['image_url']; ?>divider.gif">
</div> <?php
if($history_num>0)
{
$gift_query=mysql_query("SELECT GiftID,Name,Image FROM ".$gift_table." WHERE
Type='1'");
while($gift_info=mysql_fetch_assoc($gift_query))
{
$gift_array[$gift_info['GiftID']]['name']=$gift_info['Name'];
$gift_array[$gift_info['GiftID']]['image']=$gift_info['Image'];
} ?>
<div style=""> <?php
$i=1;
while($history_info=mysql_fetch_assoc($history_query))
{ ?>
<div style="margin-top:10px;">
<div style="float:left;width:75px;">
<img src="<?php echo
$app_info['upload_url'].$gift_array[$history_info['GiftID']]['image']; ?>"
style="width:75px;height:75px;">
</div>
<div style="float:left;margin-left:10px;">
<span style="font-size:18px;"><span id="month<?php echo $i; ?>"></span> -
Gift Received!</span><br>
You received a(n) <b><?php echo $gift_array[$history_info['GiftID']]
['name']; ?></b> from <b><fb:name uid='<?php echo $history_info['FacebookID']; ?>'
linked='false'></fb:name></b>!<br>
**************************************************************
<input id="share_button<?php echo $i; ?>" onclick="shareFeed('<?php echo
$gift_array[$history_info['GiftID']]['image']; ?>','<?php echo $history_info['GiftID'];
?>','<?php echo $gift_array[$history_info['GiftID']]['name']; ?>')" type="image" src="
<?php echo $app_info['image_url']; ?>share_button.png"
onmouseover="convert('share_button<?php echo $i; ?>','share_hover.png')"
onmouseout="convert('share_button<?php echo $i; ?>','share_button.png')"
style="height:29px;margin-top:5px;">
</div>
**************************************************************
<br style="clear:both;">
</div>
<script>
var date_text="";
var time_date=new Date();
var monthNames=
["January","February","March","April","May",
"June","July","August","September","October","November","December"];
time_date.setTime(<?php echo $history_info['Time']*1000; ?>);
document.getElementById('month<?php echo $i; ?
>').innerHTML=monthNames[time_date.getMonth()]+" "+time_date.getDate();
</script> <?php
$i++;
} ?>
</div> <?php
}
else
{ ?>
<div style="font-size:14px;font-weight:bold;margin-top:20px;" align="center">
No giftss received over the past 30 days.
</div> <?php
} ?>
</div>

Categories