Display a public Facebook event on a web page - facebook

How can I show information from a specifiec Facebook event on a webpage?
Things like: time, location, created by, more info, and also the image used as thumbnail.
Even if I didn't created that event.
Someone else created it.
I just have the url of that Facebook event and I can find the user id of the person who created it.
I found this page:
http://www.codeofaninja.com/2011/07/display-facebook-events-to-your-website.html
But it's not the same as I want, and I couldn't figure it out how to do it.
Any help is much appreciated.

What languages do you program in? say php or javascript, and i will post a quick sample?
You can use one of the many SDK's but for me the 2 that are easiest to use are the php-sdk and javascript-sdk.
https://developers.facebook.com/docs/sdks/
Using either you can just send a request to the graph api to retrieve the info about the event by its id.
https://developers.facebook.com/docs/reference/api/
https://developers.facebook.com/docs/reference/api/event/
EDIT: Sample assumes php-sdk 3.1.1 is installed and initiated. Will show 8 of the most recent events added to page or app. App Access Token is required.
<?php
$pageid='YourPageId.or.AppId';
$MEevents = $facebook->api('/'.$pageid.'/events?access_token='.$app_access_token.'&fields=id,name,from,start_time,location,end_time&limit=8');
echo '<div align="center" style="border: 0px solid; width: 100%;">';
foreach ($MEevents as $key=>$value) {
$i=1;
foreach ($value as $fkey=>$fvalue) {
if($fvalue[id]==h){
}else{
$i++;
$whofrom = $fvalue[from];
$whofromname = $whofrom[name];
$whofrompic = $whofrom[id];
echo '<div title="'.$fvalue[name].'" style="vertical-align: top; border: 1px inset; width: 700px; min-height: 80px; margin: 2px;">';
echo '<div id=""></div>';
echo '<div style="margin: 4px; padding: 3px; text-align: left;">';
echo '<img src="https://graph.facebook.com/'.$fvalue[id].'/picture" style="float: left; clear: left; margin: 5px;"> ';
echo ''.$fvalue[name].'<br />';
echo 'Location: '.$fvalue[location].'<br />';
echo 'Starts '.nicetime($fvalue[start_time]).' - Ends '.nicetime($fvalue[end_time]).'<br />';
echo '</div>';
echo '</div>';
}
}
}
echo '</div>';
?>

Related

How to send html in api parameter in flutter?

I am passing a long string of Html in the API parameter. But Html data is not inserted every time. I have rechecked the Html string again and again. I logged it and it is all right but when I pass in the API parameter, its data is not inserted...
Moreover, the postman also not allowing to pass Html in the raw body.
For example my html is:
<td id="st1showemailTextArea">
<span id="N1outerheaderwelcometext" style="color: rgb(0, 0, 0); margin-left: 5%; margin-bottom: 1%; pointer-events: none;">signature heading</span><br>
<span id="N1outerheadermiddletext" style="color: rgb(0, 0, 0); margin-left: 5%; margin-bottom: 1%;">signature sub heading</span><br>

PHP echo and onmouseover

I have this HTML code and it works perfect:
<img onmouseover="this.src='http://www.example.com.img1.jpg';" onmouseout="this.src='http://www.example.com.img2.jpg';" src="http://www.example.com.img2.jpg" alt="ALT Text" class="img-responsive"/></br>
I want to add this code in PHP and replace the link and image urls with this variables: $link, $image_src1 and $image_src2.
I tried this code:
<img onmouseover="this.src='.$image_src1.';" onmouseout="this.src='.$image_src2.';" src=".$image_src2." alt="ALT Text" class="img-responsive"/></br>
I think I can not manage how to use quotes, because of this, I am getting an error.
Thank you in advance!
Thank you #Muhammad I managed it to work with CSS and :hover
This is my code in case someone needs it:
echo '<div class="effect">';
echo '<img class="image" src="'.$image_src.'';
echo '<img class="image hover" src="'.$image_src2.'';
echo '</div>';
And the CSS:
.effect img.image{
display: block;
width: 100%;
max-width: 100%;
height: auto;
}
.effect:hover img.image{
display:none;
}
.effect img.hover{
display:none;
}
.effect:hover img.hover{
display:block;
}
Try this:
$link = 'http://www.google.com';
$image_src1 = "https://image.flaticon.com/icons/svg/148/148766.svg";
$image_src2 = "https://image.flaticon.com/icons/svg/149/149147.svg";
echo '<img onmouseover="this.src='.$image_src1.';" onmouseout="this.src='.$image_src2.';" src="'.$image_src2.'" alt="ALT Text" class="img-responsive"/></br>';
But you really need to look in your code logic, for mouseover/out. You can achieve same logic using CSS :hover property in simple and elegant way.

How do I get a current facebook access_token when accessing group events with graph api?

I have this code for accessing and displaying Facebook events from a Facebook Group. If you use a current access_token, this works but the access_tokens are only valid for an hour or so. What code do I need to add to programatically get a current access_token each time the page loads?
I have looked at the facebook advice and it puts my page into a permanant loop.
<?php
header ('Content-type: text/html; charset=utf-8');
$limit = 5;
$group_id = '68663437095';
$url1 = 'https://graph.facebook.com/'.$group_id;
$des = json_decode(file_get_contents($url1));
$url2 = "https://graph.facebook.com/68663437095/events?access_token=CAACEdEose0cBAORQs8KFqo6Fw1ZA78alt8CgH3pyKgEVWdbsxWmBhjwVqOOSqst51fb1ZCHK0Dtz8CmTDCZByqoJMoaXcEU6qjN4IO1JWExSwuHzVRmNU5JEkzpdcSuhPd8StyYSObAhXU4DKngmnHtvF018wZAmsg8GEFXNatcZAZBBMbJmsUOvwSOa7DubIZD";
$data = json_decode(file_get_contents($url2));
?>
<style type="text/css">
.wrapper {
width:200px;
border:1px solid #ccc;
font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
background-color: black;
float:left;
}
.top {
margin:5px;
border-bottom:2px solid #e1e1e1;
float: left;
width:290px;
}
.single {
margin:5px;
border-bottom:1px dashed #e1e1e1;
float:left;
}
.img {
float:left;
width:60px;
text-align:center;
margin:5px 5px 5px 0px;
border-right:1px dashed #e1e1e1;
}
.text {
width:220px;
float:left;
font-size:10px;
}
a {
text-decoration: none;
color: #3b5998;
}
</style>
<div style="width: 250px; padding-bottom:15px;"><br/>
<div style="width: 190x; margin-left:15px;">
<a target="_parent" style="font-size:40px;" href="http://www.facebook.com/groups/fumcbixby/"> <?=$des->name?></a>
<div style="width:100%; margin: 5px">
<?=$des->description?>
</div>
</div><br/>
<?
$counter = 0;
foreach($data->data as $d) {
if($counter==$limit)
break;
?>
<div style="width: auto; background-color:white; margin-left:15px; margin-bottom:15px; padding:5px">
<div style="float: left; width:120px;">
<img src="https://graph.facebook.com/<?= $d->id?>/picture">
</div>
<div>
<h2>Name <?= $d->name?></h2>
<h3>Location <?= $d->location?></h3>
<p>Start<?= date('F j, Y H:i',strtotime($d->start_time))?></p>
<p>End<?= date('F j, Y H:i',strtotime($d->end_time))?></p>
Visit Event
</div>
</div>
<?
$counter++;
}
?>
</div>
Get Extended Access Token which will be valid for 60 days
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN
Put APP_ID, APP_SECRET & EXISTING_ACCESS_TOKEN in the above url & make a HTTP request.
HTTP request will return JSON Array. Then you can easily parse Extended Access Token
Have a look at this question....
How to renew/extend facebook access tokens with PHP?

Remove ~20px gap at right side of HTML mail on iOS

Recently I have been working on a contact form for my portfolio website. The form works and I have managed to successfully send HTML mail from the server it's hosted on to my email address. Like most of my emails, these will be primarily read on my iPod Touch so the theme I based the mail template on is engineered for a screen 320px by 480px.
Even though the mail container element is set to width:100% and the same on all inner elements, there is a ~20px gap at the right side of the screen, as if that's the edge of the document:
Here is the script and style-sheet for reference:
PHP (snippet), request_form.php:
...
$email_subject = "Graphic Request - ".clean_string($first_name);
$email_message .= '<html><head><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/><link rel="stylesheet" href="http://blieque.comli.com/mail-styles.css" type="text/css"></head><body><table id="all" cellspacing="0" cellpadding="0">';
$email_message .= '<tr><td id="head"><h1>New Request</h1></td></tr>';
$email_message .= '<tr><td class="info"><span id="param">Name:</span> '.clean_string($first_name).'</td></tr>';
$email_message .= '<tr><td class="info sub"><span id="param">Email Address:</span> '.clean_string($email_from).'</td></tr>';
$email_message .= '<tr><td class="info sub"><span id="param">Service:</span> '.clean_string($service).'</td></tr>';
$email_message .= '<tr><td class="info sub jstfy"><span id="param">Details:</span> '.clean_string($request).'</td></tr>';
$email_message .= '<tr><td id="foot"></td></tr></table></body></html>';
...
CSS, mail-styles.css:
body {
margin: 0 !important;
font-family: Arial, Helvetica, sans-serif;
color: #242424 !important;
text-decoration: none !important;
}
#all {
width: 110%;
}
#head {
background: #1393A1;
color: #61BDC7;
border-bottom: solid 0.5em #61BDC7;
width: 100%;
padding: 1em 0.5em;
height: 20px;
}
td.sub {
border-top: solid 0.25em #1393a1;
}
td.info {
padding: 0.35em 0.5em;
font-size: 12pt;
}
td.jstfy {
text-align: justify;
}
span#param {
color: #1393a1;
font-weight: bold;
}
td[class=info] {
text-transform: capitalize;
}
#foot {
background: #1393a1;
width: 100%;
height: 20px;
color: transparent;
border-top: solid 0.5em #61BDC7;
}
#line {
background: #1393a1;
width: 94%;
height: 0.25em;
margin-left: auto;
margin-right: auto;
}
The email also doesn't work well with online email viewers as they tend to have their own overriding style-sheets for common tags like <h1>. I hope the solution is something obvious.
This worked for me:
html, body {
width: 100%;
padding: 0;
margin: 0;
}
When I used min-width instead of width, the content got too wide. I also have these viewport settings in my header:
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
You could try adding min-width: 100% to the <body> element to deal with the gap.
And as the others suggested, moving your styles inline should deal with the rest of your problems.
Maybe try
html, body {
margin: 0;
padding: 0;
}
HTML emails don't handle external stylesheets very well so this may be your problem.
You should only use inline styles on HTML emails as a general rule of thumb.
Here's a good guide on HTML emails:
http://kb.mailchimp.com/article/how-to-code-html-emails
This is happening because body has padding by default on most browsers. add:
body{
padding:0px;
}
I've dealt with this issue numerous times. Every time it occurs I always realize that it's happening because I'm using cellpadding incorrectly on one of my tables.
For example, I got caught up for a bit today because near the bottom of one of the emails I was working on there is a table with a press banner that stretches horizontally across the bottom like this:
<center><!-- Press Banner -->
<table border="0" cellpadding="15" cellspacing="0" bgcolor="#ffffff">
<tr>
<td align="center">
<a role="link" href="#" target="_blank" title="#">
<span class="press">
<img class="desktop" src="#" border="0" style="display:block;">
</span>
</a>
</td>
</tr>
</table>
</center>
That image is 600 pixels wide and is switched for a 320 pixel wide background image for the mobile layout. I needed to add some vertical spacing between that block and the others so I chose to add cellpadding="15" to do so, without realizing that 15 pixels would also stretch out horizontally. But on the iOS device this is extra space only renders on the right side, not the left, so its not obvious what the problem is.
To fix it, I removed the cellpadding and used table spacers instead on the top and bottom.
<tr>
<td><table border="0" cellpadding="6" cellspacing="0"><tr><td height="4"><table border="0" cellpadding="0" cellspacing="0"><tr><td></td></tr></table></td></tr></table></td>
</tr>
There are many other reasons that this issue could occur as other people have already mentioned, but just adding this potential cause for anyone else who may be overlooking the same error that I made.
Additionally as a rule of thumb, you should never import CSS in an HTML email, you should inline as much style as possible and use depreciated CSS2 tags and oldschool HTML styling elements whenever possible to achieve the highest level of cross device, client compability. I recently uploaded a project to github(link) which is the html email template I've created while building emails for some time. It's pretty much the most compatible template you'll find anywhere.

Problem with Wordpress' div class="Post", "Entry" and "postmetadata"

Im having trouble with my codes in wordpress. You can see my problem in the link below:
http://i1204.photobucket.com/albums/bb409/bendaggers/help-1.png
as you can see, i'm having trouble sticking them all together
the CSS codes are here:
.post{
padding: 10px 0 0 0px;
background-image: url(images/toppost.png);
background-repeat:no-repeat;
}
.entry{
background-image:url(images/ContentBG.png);
margin: 0 0 0 0;
padding:0 0 0 0;
background-position: bottom;
}
.postmetadata {
clear: both;
background-image: url(images/post-footer.png);
background-repeat:no-repeat;
height:118px;
}
the php codes are here:
<div id="container">
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?> </h2>
</div>
<div class="entry">
<?php the_content(); ?></div>
<p class="postmetadata">
<?php _e('Filed under:'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php the_author(); ?><br />
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>
</p>
<?php endwhile; ?>
can you help me with my problem? its taking me so looong to solve this one coz im still a newbie in wordpress.
thanks in advance.
You need to add padding to your classes:
.post{
padding: 10px 5px 0 5px;
background-image: url(images/toppost.png);
background-repeat:no-repeat;
}
.entry{
background-image:url(images/ContentBG.png);
margin: 0 0 0 0;
padding:0 5px;
background-position: bottom;
}
.postmetadata {
clear: both;
background-image: url(images/post-footer.png);
background-repeat:no-repeat;
height:118px;
padding:0 5px;
}