Online Marketing Strategy for Results

Facebook Cover Photo for Timeline and Pages

Posted on: February 29th, 2012 by Skip Shean 3 Comments

 

Facebook Cover Photo, part of the Timeline feature set,  gives people and now businesses a way to visually communicate who they are with others rapidly.  This post will give you a Photoshop template for creating your Facebook Timeline image and a few ideas of how to design it, if you're not a professional graphic designer.

I believe that Facebook is an incredible platform for reaching the people who are interested in topics that you share -- it's not that interesting that there are almost a billion people on Facebook -- it's that there is your specific prospective audience that are share your passion for LOLCATS or natural wellness or options trading.  Your 25,000 possible audience, let's say, instead of trying to have a conversation with 850 million of your closest friends.

What Is Timeline?

Introduced late in 2011, Timeline initially came to Facebook's pages for individuals, not businesses.  The broad cover image gave people a way to show something that inspired, amused, or represented them -- in an image that is 851 x 315 pixels.

There were some great efforts made by individuals on their pages.  Here's a few I like for your inspiration:

lev hover Facebook Cover Photo for Timeline and Pages

(Image Source: Lev Detrez – Facebook.com)

 

eduardo calvo best creative facebook timeline design Facebook Cover Photo for Timeline and Pages

(Image Source: Eduardo Calvo – Facebook.com)

 

butterfinger Facebook Cover Photo for Timeline and Pages

(Image Source: Butterfinger – Facebook.com)

modernfamily Facebook Cover Photo for Timeline and Pages

(Image Source: Modern Family – Facebook.com)

Download Facebook Cover Image Template

Without further ado, download a photoshop template for facebook timeline images here.

Some specifications you may want to have handy:

  • The cover image itself is 851 x 315 pixels
  • The square profile thumbnail image is 180 x 180 pixels.
  • You want to be careful on the profile thumbnail, because it gets sized down to 32 x 32 pixels on posts, so don't cram small text in there -- hopefully you have a graphical representation of yourself or your brand you can use.

Creating A Facebook Cover Photo for Pages

I'm not assuming anything about your knowledge of Photoshop here, so if you're an advanced PS designer, just skip this part.  This is for our n00b friends.  Be nice to them.

After you open the template in Photoshop or GIMP, you'll notice I put a lot of screen elements from Facebook in there so you can visualize how things will line up when the image is live.

But you won't want to save all of that gunk when it's time to save your image and upload it to your Facebook page for your business, obviously.

After you've got your image ready to go, turn off the visibility of all the elements you don't want to save:

photoshop preflight Facebook Cover Photo for Timeline and Pages

 

Then click on the File menu and select "Save for Web and Devices..."  Choose the "slices" icon at top left to make sure you know which slice number you want to save.  Click on the main image to select that user slice.  I like to look carefully at the different ways to save -- PNG-8 vs. JPEG vs. PNG-24 -- and make the choices and tradeoffs for image quality versus image size.  Remember to make your images as small as possible while keeping the quality acceptable.

Once you know the format you want to save the image in, click the Save button below.

save for web1 Facebook Cover Photo for Timeline and Pages

 

In the Save window, name your file and change the dropdown at the bottom to "Selected Slices".

SaveSelectedSlices Facebook Cover Photo for Timeline and Pages

 

After you've saved your image in the desired format, upload it to your Facebook cover photo and you're all done!  You're rockin' a brand-new Facebook cover photo.  Congrats!

 

 

Build a Facebook Page that Changes When Like Is Clicked

Posted on: January 9th, 2012 by Skip Shean 6 Comments

 

IMG 0340 300x288 Build a Facebook Page that Changes When Like Is ClickedA Facebook App and Custom Welcome Tab for Your New Page Visitors

Facebook is a great place for many small businesses to engage with existing customers and to find prospective new customers.  This article will walk you through creating your own custom tab on Facebook that changes when the visitor clicks the Facebook Like Button, a type of a Facebook page called a Reveal Tab.

This article is a bit on the technical side, but if you can handle some basic HTML code you can probably work your way through it.

  • You'll need a program that lets you edit HTML, such as Dreamweaver or iWeb.
  • You might also want to have access to a graphics editor such as Photoshop or GIMP to do the graphics for your own page.
  • You need to have the ability to host web pages securely via HTTPS, because Facebook requires secure pages
  • I'm assuming that you've already created your Facebook Page itself and are looking to add a Custom Welcome Tab to it.

Four web pages to build a Facebook Page

There are four pages that you will create on your own server to make up the reveal tab.  For this demo, they will be named:

  • index.php
  • facebook.php
  • prelike.php
  • reveal.php

Create a blank document with each of these names in the location where you are going to host them publicly.

You will also create an App on Facebook's Developer website that integrates these pages with your Facebook page for your business.

In very short form, here's the purpose of each file:

Index.php

This page is the center of the Facebook page.  It links to the Facebook App to enable the Facebook page to put the right information on the page depending on whether the visitor has clicked Like or not.

Facebook.php

This is what is called the Facebook "SDK" or Software Development Kit.  It's code that Facebook has provided you to enable these sorts of custom applications.  All you'll do is cut and paste it in and save the page in the right directory.

Prelike.php

This is the content that will be displayed to the visitor before they click the Like button

Reveal.php

This is the content that will be displayed to the user after they click the Like button.

Note:

The two files "prelike.php" and "reveal.php" do not require that the files be in PHP, you could make them HTML or anything else you'd like and that your webserver can serve -- but index.php and facebook.php DO require PHP to function properly.

 

Download Post Files

All of the files in this post are in this zip file for your convenience:  code.zip

 

Create a Facebook App

1. The first step in the process is to create a Facebook application.  Go to http://developers.facebook.com.  Select "Apps" along the top menu bar.

developers home Build a Facebook Page that Changes When Like Is Clicked

http://developers.facebook.com

 

2.  Click on "Create New App" at the top right

create new app Build a Facebook Page that Changes When Like Is Clicked

Create a new Facebook app

 

3.  Grant Facebook permissions to give you access to the Developer tools, if you haven't already done so:

developers permission Build a Facebook Page that Changes When Like Is Clicked

Click Allow

 

4.  A popup will ask you to name your new app and give it a namespace.  The App Display Name will be shown to the end users of your application, so make it a friendly name that is descriptive.  The namespace is not shown to users.  Both names must be unique.

name app Build a Facebook Page that Changes When Like Is Clicked

Name the new Facebook app

Click that you agree to the Facebook Platform Policies and click "Continue".

 

4. You'll be taken to your new a page that allows you to edit your brand new Facebook app settings, that looks like this:

app edit settings Build a Facebook Page that Changes When Like Is Clicked

 

5.  Lower down on the edit page, check the box for "Page Tab"

facebook page tab settings Build a Facebook Page that Changes When Like Is Clicked

Facebook app page tab settings

There are three fields that must be filled in on Page Tab:

  • Page Tab Name:  This is what the user will see on the left menu on your Facebook page.
  • Page Tab URL:  This is where the index.php page is hosted.  May be non-secure
  • Secure Page Tab URL [Required]: Must be an HTTPS address.  Where the index.php page is located.

If you created the pages as requested at the beginning of the post, you can put those URLs in from where you have them hosted.

One other note on where these pages you create live.  It personally drives me insane when a company creates a fancy Facebook welcome page, then doesn't do everything they can to make it load quickly.  I like putting the images, especially larger images on Amazon's S3 service, and cacheing the site in every way possible to optimize the quick serving of this page.

If you haven't used anything like that before, exhale.  All it is is a big hard drive in the sky (well, LOTS of hard drives scattered worldwide).  Using S3 will allow you to have pages that are secure, and will also be lightning-fast for the user.  At one point they would even give you something like 40GB of transfer per month for free, too, so your costs should be next to nothing.

Now that you've set up the app and entered your index page, click Save Changes and...let's add the new Facebook App to your Facebook Page.

Add App to Your Facebook Page

To do this, you simply use the following URL (see this page for more info):

https://www.facebook.com/dialog/pagetab?app_id=YOUR_APP_ID&next=YOUR_URL

where YOUR_APP_ID and YOUR_URL can be found in your app settings.  (Specifically, YOUR_URL refers to the "Secure Page Tab URL" field).  If you do this correctly, the following popup will appear.  Choose your desired page from the drop down menu and click "Add Page Tab".

Screen Shot 2012 01 09 at 9.52.52 AM Build a Facebook Page that Changes When Like Is Clicked

Add To Page Dialog

 

Now let's create the pages.

 

The Code

Create a new web page in your HTML editor and name it index.php.  Paste the code below into it:

Index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!--?php </p>-->

// Refer to http://16wells.com/build-a-reveal-tab-for-your-facebook-page for configuration

require 'facebook.php';

$app_id = "YOUR_APP_ID";
$app_secret = "YOUR_APP_SECRET";
$facebook = new Facebook(array(
'appId' =&gt; $app_id,
'secret' =&gt; $app_secret,
'cookie' =&gt; true
));

$signed_request = $facebook-&gt;getSignedRequest();

$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];

// The following statement does a test of $like_status and chooses which page to display to the visitor
if ($like_status) {$a = file_get_contents("reveal.php");
echo ($a);
}
else {$a = file_get_contents("prelike.php");
echo ($a);
}

?&gt;

Save the file and upload it to the folder where you'll be hosting them.

Prelike.php

Same drill...name this one prelike.php...code below:

1
2
<div id="not-fans"><!-- This image will be displayed to people who aren't fans -->
<img id="not-fans" src="https://s3.amazonaws.com/cdn.16wells.com/facebook/reveal-before.png" alt="" /></div>

Reveal.php

Create another new web page in your HTML editor and name it, reveal.php.  Here's the code:

1
2
3
4
5
<div id="wrapper">
<div style="width: 520px;"><!-- This image will be displayed to fans -->
<img src="https://s3.amazonaws.com/cdn.16wells.com/facebook/reveal-after.png" alt="" />
<!-- You can also add or replace with any HTML that you want displayed to fans --></div>
</div>

Facebook.php

And create and name the final file in the group, facebook.php.  Paste the code below into it. (This one's really long...sorry...it's the Facebook code to handle the interaction between your pages and Facebook) Remember you can download all of these files here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
*/
class FacebookApiException extends Exception
{
/**
* The result from the API server that represents the exception information.
*/
protected $result;

/**
* Make a new API Exception with the given result.
*
* @param Array $result the result from the API server
*/
public function __construct($result) {
$this-&gt;result = $result;

$code = isset($result['error_code']) ? $result['error_code'] : 0;

if (isset($result['error_description'])) {
// OAuth 2.0 Draft 10 style
$msg = $result['error_description'];
} else if (isset($result['error']) &amp;&amp; is_array($result['error'])) {
// OAuth 2.0 Draft 00 style
$msg = $result['error']['message'];
} else if (isset($result['error_msg'])) {
// Rest server style
$msg = $result['error_msg'];
} else {
$msg = 'Unknown Error. Check getResult()';
}

parent::__construct($msg, $code);
}

/**
* Return the associated result object returned by the API server.
*
* @returns Array the result from the API server
*/
public function getResult() {
return $this-&gt;result;
}

/**
* Returns the associated type for the error. This will default to
* 'Exception' when a type is not available.
*
* @return String
*/
public function getType() {
if (isset($this-&gt;result['error'])) {
$error = $this-&gt;result['error'];
if (is_string($error)) {
// OAuth 2.0 Draft 10 style
return $error;
} else if (is_array($error)) {
// OAuth 2.0 Draft 00 style
if (isset($error['type'])) {
return $error['type'];
}
}
}
return 'Exception';
}

/**
* To make debugging easier.
*
* @returns String the string representation of the error
*/
public function __toString() {
$str = $this-&gt;getType() . ': ';
if ($this-&gt;code != 0) {
$str .= $this-&gt;code . ': ';
}
return $str . $this-&gt;message;
}
}

/**
* Provides access to the Facebook Platform.
*
* @author Naitik Shah
*/
class Facebook
{
/**
* Version.
*/
const VERSION = '2.1.2';

/**
* Default options for curl.
*/
public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT =&gt; 10,
CURLOPT_RETURNTRANSFER =&gt; true,
CURLOPT_TIMEOUT =&gt; 60,
CURLOPT_USERAGENT =&gt; 'facebook-php-2.0',
);

/**
* List of query parameters that get automatically dropped when rebuilding
* the current URL.
*/
protected static $DROP_QUERY_PARAMS = array(
'session',
'signed_request',
);

/**
* Maps aliases to Facebook domains.
*/
public static $DOMAIN_MAP = array(
'api' =&gt; 'https://api.facebook.com/',
'api_read' =&gt; 'https://api-read.facebook.com/',
'graph' =&gt; 'https://graph.facebook.com/',
'www' =&gt; 'https://www.facebook.com/',
);

/**
* The Application ID.
*/
protected $appId;

/**
* The Application API Secret.
*/
protected $apiSecret;

/**
* The active user session, if one is available.
*/
protected $session;

/**
* The data from the signed_request token.
*/
protected $signedRequest;

/**
* Indicates that we already loaded the session as best as we could.
*/
protected $sessionLoaded = false;

/**
* Indicates if Cookie support should be enabled.
*/
protected $cookieSupport = false;

/**
* Base domain for the Cookie.
*/
protected $baseDomain = '';

/**
* Indicates if the CURL based @ syntax for file uploads is enabled.
*/
protected $fileUploadSupport = false;

/**
* Initialize a Facebook Application.
*
* The configuration:
* - appId: the application ID
* - secret: the application secret
* - cookie: (optional) boolean true to enable cookie support
* - domain: (optional) domain for the cookie
* - fileUpload: (optional) boolean indicating if file uploads are enabled
*
* @param Array $config the application configuration
*/
public function __construct($config) {
$this-&gt;setAppId($config['appId']);
$this-&gt;setApiSecret($config['secret']);
if (isset($config['cookie'])) {
$this-&gt;setCookieSupport($config['cookie']);
}
if (isset($config['domain'])) {
$this-&gt;setBaseDomain($config['domain']);
}
if (isset($config['fileUpload'])) {
$this-&gt;setFileUploadSupport($config['fileUpload']);
}
}

/**
* Set the Application ID.
*
* @param String $appId the Application ID
*/
public function setAppId($appId) {
$this-&gt;appId = $appId;
return $this;
}

/**
* Get the Application ID.
*
* @return String the Application ID
*/
public function getAppId() {
return $this-&gt;appId;
}

/**
* Set the API Secret.
*
* @param String $appId the API Secret
*/
public function setApiSecret($apiSecret) {
$this-&gt;apiSecret = $apiSecret;
return $this;
}

/**
* Get the API Secret.
*
* @return String the API Secret
*/
public function getApiSecret() {
return $this-&gt;apiSecret;
}

/**
* Set the Cookie Support status.
*
* @param Boolean $cookieSupport the Cookie Support status
*/
public function setCookieSupport($cookieSupport) {
$this-&gt;cookieSupport = $cookieSupport;
return $this;
}

/**
* Get the Cookie Support status.
*
* @return Boolean the Cookie Support status
*/
public function useCookieSupport() {
return $this-&gt;cookieSupport;
}

/**
* Set the base domain for the Cookie.
*
* @param String $domain the base domain
*/
public function setBaseDomain($domain) {
$this-&gt;baseDomain = $domain;
return $this;
}

/**
* Get the base domain for the Cookie.
*
* @return String the base domain
*/
public function getBaseDomain() {
return $this-&gt;baseDomain;
}

/**
* Set the file upload support status.
*
* @param String $domain the base domain
*/
public function setFileUploadSupport($fileUploadSupport) {
$this-&gt;fileUploadSupport = $fileUploadSupport;
return $this;
}

/**
* Get the file upload support status.
*
* @return String the base domain
*/
public function useFileUploadSupport() {
return $this-&gt;fileUploadSupport;
}

/**
* Get the data from a signed_request token
*
* @return String the base domain
*/
public function getSignedRequest() {
if (!$this-&gt;signedRequest) {
if (isset($_REQUEST['signed_request'])) {
$this-&gt;signedRequest = $this-&gt;parseSignedRequest(
$_REQUEST['signed_request']);
}
}
return $this-&gt;signedRequest;
}

/**
* Set the Session.
*
* @param Array $session the session
* @param Boolean $write_cookie indicate if a cookie should be written. this
* value is ignored if cookie support has been disabled.
*/
public function setSession($session=null, $write_cookie=true) {
$session = $this-&gt;validateSessionObject($session);
$this-&gt;sessionLoaded = true;
$this-&gt;session = $session;
if ($write_cookie) {
$this-&gt;setCookieFromSession($session);
}
return $this;
}

/**
* Get the session object. This will automatically look for a signed session
* sent via the signed_request, Cookie or Query Parameters if needed.
*
* @return Array the session
*/
public function getSession() {
if (!$this-&gt;sessionLoaded) {
$session = null;
$write_cookie = true;

// try loading session from signed_request in $_REQUEST
$signedRequest = $this-&gt;getSignedRequest();
if ($signedRequest) {
// sig is good, use the signedRequest
$session = $this-&gt;createSessionFromSignedRequest($signedRequest);
}

// try loading session from $_REQUEST
if (!$session &amp;&amp; isset($_REQUEST['session'])) {
$session = json_decode(
get_magic_quotes_gpc()
? stripslashes($_REQUEST['session'])
: $_REQUEST['session'],
true
);
$session = $this-&gt;validateSessionObject($session);
}

// try loading session from cookie if necessary
if (!$session &amp;&amp; $this-&gt;useCookieSupport()) {
$cookieName = $this-&gt;getSessionCookieName();
if (isset($_COOKIE[$cookieName])) {
$session = array();
parse_str(trim(
get_magic_quotes_gpc()
? stripslashes($_COOKIE[$cookieName])
: $_COOKIE[$cookieName],
'"'
), $session);
$session = $this-&gt;validateSessionObject($session);
// write only if we need to delete a invalid session cookie
$write_cookie = empty($session);
}
}

$this-&gt;setSession($session, $write_cookie);
}

return $this-&gt;session;
}

/**
* Get the UID from the session.
*
* @return String the UID if available
*/
public function getUser() {
$session = $this-&gt;getSession();
return $session ? $session['uid'] : null;
}

/**
* Gets a OAuth access token.
*
* @return String the access token
*/
public function getAccessToken() {
$session = $this-&gt;getSession();
// either user session signed, or app signed
if ($session) {
return $session['access_token'];
} else {
return $this-&gt;getAppId() .'|'. $this-&gt;getApiSecret();
}
}

/**
* Get a Login URL for use with redirects. By default, full page redirect is
* assumed. If you are using the generated URL with a window.open() call in
* JavaScript, you can pass in display=popup as part of the $params.
*
* The parameters:
* - next: the url to go to after a successful login
* - cancel_url: the url to go to after the user cancels
* - req_perms: comma separated list of requested extended perms
* - display: can be "page" (default, full page) or "popup"
*
* @param Array $params provide custom parameters
* @return String the URL for the login flow
*/
public function getLoginUrl($params=array()) {
$currentUrl = $this-&gt;getCurrentUrl();
return $this-&gt;getUrl(
'www',
'login.php',
array_merge(array(
'api_key' =&gt; $this-&gt;getAppId(),
'cancel_url' =&gt; $currentUrl,
'display' =&gt; 'page',
'fbconnect' =&gt; 1,
'next' =&gt; $currentUrl,
'return_session' =&gt; 1,
'session_version' =&gt; 3,
'v' =&gt; '1.0',
), $params)
);
}

/**
* Get a Logout URL suitable for use with redirects.
*
* The parameters:
* - next: the url to go to after a successful logout
*
* @param Array $params provide custom parameters
* @return String the URL for the logout flow
*/
public function getLogoutUrl($params=array()) {
return $this-&gt;getUrl(
'www',
'logout.php',
array_merge(array(
'next' =&gt; $this-&gt;getCurrentUrl(),
'access_token' =&gt; $this-&gt;getAccessToken(),
), $params)
);
}

/**
* Get a login status URL to fetch the status from facebook.
*
* The parameters:
* - ok_session: the URL to go to if a session is found
* - no_session: the URL to go to if the user is not connected
* - no_user: the URL to go to if the user is not signed into facebook
*
* @param Array $params provide custom parameters
* @return String the URL for the logout flow
*/
public function getLoginStatusUrl($params=array()) {
return $this-&gt;getUrl(
'www',
'extern/login_status.php',
array_merge(array(
'api_key' =&gt; $this-&gt;getAppId(),
'no_session' =&gt; $this-&gt;getCurrentUrl(),
'no_user' =&gt; $this-&gt;getCurrentUrl(),
'ok_session' =&gt; $this-&gt;getCurrentUrl(),
'session_version' =&gt; 3,
), $params)
);
}

/**
* Make an API call.
*
* @param Array $params the API call parameters
* @return the decoded response
*/
public function api(/* polymorphic */) {
$args = func_get_args();
if (is_array($args[0])) {
return $this-&gt;_restserver($args[0]);
} else {
return call_user_func_array(array($this, '_graph'), $args);
}
}

/**
* Invoke the old restserver.php endpoint.
*
* @param Array $params method call object
* @return the decoded response object
* @throws FacebookApiException
*/
protected function _restserver($params) {
// generic application level parameters
$params['api_key'] = $this-&gt;getAppId();
$params['format'] = 'json-strings';

$result = json_decode($this-&gt;_oauthRequest(
$this-&gt;getApiUrl($params['method']),
$params
), true);

// results are returned, errors are thrown
if (is_array($result) &amp;&amp; isset($result['error_code'])) {
throw new FacebookApiException($result);
}
return $result;
}

/**
* Invoke the Graph API.
*
* @param String $path the path (required)
* @param String $method the http method (default 'GET')
* @param Array $params the query/post data
* @return the decoded response object
* @throws FacebookApiException
*/
protected function _graph($path, $method='GET', $params=array()) {
if (is_array($method) &amp;&amp; empty($params)) {
$params = $method;
$method = 'GET';
}
$params['method'] = $method; // method override as we always do a POST

$result = json_decode($this-&gt;_oauthRequest(
$this-&gt;getUrl('graph', $path),
$params
), true);

// results are returned, errors are thrown
if (is_array($result) &amp;&amp; isset($result['error'])) {
$e = new FacebookApiException($result);
switch ($e-&gt;getType()) {
// OAuth 2.0 Draft 00 style
case 'OAuthException':
// OAuth 2.0 Draft 10 style
case 'invalid_token':
$this-&gt;setSession(null);
}
throw $e;
}
return $result;
}

/**
* Make a OAuth Request
*
* @param String $path the path (required)
* @param Array $params the query/post data
* @return the decoded response object
* @throws FacebookApiException
*/
protected function _oauthRequest($url, $params) {
if (!isset($params['access_token'])) {
$params['access_token'] = $this-&gt;getAccessToken();
}

// json_encode all params values that are not strings
foreach ($params as $key =&gt; $value) {
if (!is_string($value)) {
$params[$key] = json_encode($value);
}
}
return $this-&gt;makeRequest($url, $params);
}

/**
* Makes an HTTP request. This method can be overriden by subclasses if
* developers want to do fancier things or use something other than curl to
* make the request.
*
* @param String $url the URL to make the request to
* @param Array $params the parameters to use for the POST body
* @param CurlHandler $ch optional initialized curl handle
* @return String the response text
*/
protected function makeRequest($url, $params, $ch=null) {
if (!$ch) {
$ch = curl_init();
}

$opts = self::$CURL_OPTS;
if ($this-&gt;useFileUploadSupport()) {
$opts[CURLOPT_POSTFIELDS] = $params;
} else {
$opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&amp;');
}
$opts[CURLOPT_URL] = $url;

// disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
// for 2 seconds if the server does not support this header.
if (isset($opts[CURLOPT_HTTPHEADER])) {
$existing_headers = $opts[CURLOPT_HTTPHEADER];
$existing_headers[] = 'Expect:';
$opts[CURLOPT_HTTPHEADER] = $existing_headers;
} else {
$opts[CURLOPT_HTTPHEADER] = array('Expect:');
}

curl_setopt_array($ch, $opts);
$result = curl_exec($ch);

if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
self::errorLog('Invalid or no certificate authority found, using bundled information');
curl_setopt($ch, CURLOPT_CAINFO,
dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
$result = curl_exec($ch);
}

if ($result === false) {
$e = new FacebookApiException(array(
'error_code' =&gt; curl_errno($ch),
'error' =&gt; array(
'message' =&gt; curl_error($ch),
'type' =&gt; 'CurlException',
),
));
curl_close($ch);
throw $e;
}
curl_close($ch);
return $result;
}

/**
* The name of the Cookie that contains the session.
*
* @return String the cookie name
*/
protected function getSessionCookieName() {
return 'fbs_' . $this-&gt;getAppId();
}

/**
* Set a JS Cookie based on the _passed in_ session. It does not use the
* currently stored session -- you need to explicitly pass it in.
*
* @param Array $session the session to use for setting the cookie
*/
protected function setCookieFromSession($session=null) {
if (!$this-&gt;useCookieSupport()) {
return;
}

$cookieName = $this-&gt;getSessionCookieName();
$value = 'deleted';
$expires = time() - 3600;
$domain = $this-&gt;getBaseDomain();
if ($session) {
$value = '"' . http_build_query($session, null, '&amp;') . '"';
if (isset($session['base_domain'])) {
$domain = $session['base_domain'];
}
$expires = $session['expires'];
}

// prepend dot if a domain is found
if ($domain) {
$domain = '.' . $domain;
}

// if an existing cookie is not set, we dont need to delete it
if ($value == 'deleted' &amp;&amp; empty($_COOKIE[$cookieName])) {
return;
}

if (headers_sent()) {
self::errorLog('Could not set cookie. Headers already sent.');

// ignore for code coverage as we will never be able to setcookie in a CLI
// environment
// @codeCoverageIgnoreStart
} else {
setcookie($cookieName, $value, $expires, '/', $domain);
}
// @codeCoverageIgnoreEnd
}

/**
* Validates a session_version=3 style session object.
*
* @param Array $session the session object
* @return Array the session object if it validates, null otherwise
*/
protected function validateSessionObject($session) {
// make sure some essential fields exist
if (is_array($session) &amp;&amp;
isset($session['uid']) &amp;&amp;
isset($session['access_token']) &amp;&amp;
isset($session['sig'])) {
// validate the signature
$session_without_sig = $session;
unset($session_without_sig['sig']);
$expected_sig = self::generateSignature(
$session_without_sig,
$this-&gt;getApiSecret()
);
if ($session['sig'] != $expected_sig) {
self::errorLog('Got invalid session signature in cookie.');
$session = null;
}
// check expiry time
} else {
$session = null;
}
return $session;
}

/**
* Returns something that looks like our JS session object from the
* signed token's data
*
* TODO: Nuke this once the login flow uses OAuth2
*
* @param Array the output of getSignedRequest
* @return Array Something that will work as a session
*/
protected function createSessionFromSignedRequest($data) {
if (!isset($data['oauth_token'])) {
return null;
}

$session = array(
'uid' =&gt; $data['user_id'],
'access_token' =&gt; $data['oauth_token'],
'expires' =&gt; $data['expires'],
);

// put a real sig, so that validateSignature works
$session['sig'] = self::generateSignature(
$session,
$this-&gt;getApiSecret()
);

return $session;
}

/**
* Parses a signed_request and validates the signature.
* Then saves it in $this-&gt;signed_data
*
* @param String A signed token
* @param Boolean Should we remove the parts of the payload that
* are used by the algorithm?
* @return Array the payload inside it or null if the sig is wrong
*/
protected function parseSignedRequest($signed_request) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);

// decode the data
$sig = self::base64UrlDecode($encoded_sig);
$data = json_decode(self::base64UrlDecode($payload), true);

if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
self::errorLog('Unknown algorithm. Expected HMAC-SHA256');
return null;
}

// check sig
$expected_sig = hash_hmac('sha256', $payload,
$this-&gt;getApiSecret(), $raw = true);
if ($sig !== $expected_sig) {
self::errorLog('Bad Signed JSON signature!');
return null;
}

return $data;
}

/**
* Build the URL for api given parameters.
*
* @param $method String the method name.
* @return String the URL for the given parameters
*/
protected function getApiUrl($method) {
static $READ_ONLY_CALLS =
array('admin.getallocation' =&gt; 1,
'admin.getappproperties' =&gt; 1,
'admin.getbannedusers' =&gt; 1,
'admin.getlivestreamvialink' =&gt; 1,
'admin.getmetrics' =&gt; 1,
'admin.getrestrictioninfo' =&gt; 1,
'application.getpublicinfo' =&gt; 1,
'auth.getapppublickey' =&gt; 1,
'auth.getsession' =&gt; 1,
'auth.getsignedpublicsessiondata' =&gt; 1,
'comments.get' =&gt; 1,
'connect.getunconnectedfriendscount' =&gt; 1,
'dashboard.getactivity' =&gt; 1,
'dashboard.getcount' =&gt; 1,
'dashboard.getglobalnews' =&gt; 1,
'dashboard.getnews' =&gt; 1,
'dashboard.multigetcount' =&gt; 1,
'dashboard.multigetnews' =&gt; 1,
'data.getcookies' =&gt; 1,
'events.get' =&gt; 1,
'events.getmembers' =&gt; 1,
'fbml.getcustomtags' =&gt; 1,
'feed.getappfriendstories' =&gt; 1,
'feed.getregisteredtemplatebundlebyid' =&gt; 1,
'feed.getregisteredtemplatebundles' =&gt; 1,
'fql.multiquery' =&gt; 1,
'fql.query' =&gt; 1,
'friends.arefriends' =&gt; 1,
'friends.get' =&gt; 1,
'friends.getappusers' =&gt; 1,
'friends.getlists' =&gt; 1,
'friends.getmutualfriends' =&gt; 1,
'gifts.get' =&gt; 1,
'groups.get' =&gt; 1,
'groups.getmembers' =&gt; 1,
'intl.gettranslations' =&gt; 1,
'links.get' =&gt; 1,
'notes.get' =&gt; 1,
'notifications.get' =&gt; 1,
'pages.getinfo' =&gt; 1,
'pages.isadmin' =&gt; 1,
'pages.isappadded' =&gt; 1,
'pages.isfan' =&gt; 1,
'permissions.checkavailableapiaccess' =&gt; 1,
'permissions.checkgrantedapiaccess' =&gt; 1,
'photos.get' =&gt; 1,
'photos.getalbums' =&gt; 1,
'photos.gettags' =&gt; 1,
'profile.getinfo' =&gt; 1,
'profile.getinfooptions' =&gt; 1,
'stream.get' =&gt; 1,
'stream.getcomments' =&gt; 1,
'stream.getfilters' =&gt; 1,
'users.getinfo' =&gt; 1,
'users.getloggedinuser' =&gt; 1,
'users.getstandardinfo' =&gt; 1,
'users.hasapppermission' =&gt; 1,
'users.isappuser' =&gt; 1,
'users.isverified' =&gt; 1,
'video.getuploadlimits' =&gt; 1);
$name = 'api';
if (isset($READ_ONLY_CALLS[strtolower($method)])) {
$name = 'api_read';
}
return self::getUrl($name, 'restserver.php');
}

/**
* Build the URL for given domain alias, path and parameters.
*
* @param $name String the name of the domain
* @param $path String optional path (without a leading slash)
* @param $params Array optional query parameters
* @return String the URL for the given parameters
*/
protected function getUrl($name, $path='', $params=array()) {
$url = self::$DOMAIN_MAP[$name];
if ($path) {
if ($path[0] === '/') {
$path = substr($path, 1);
}
$url .= $path;
}
if ($params) {
$url .= '?' . http_build_query($params, null, '&amp;');
}
return $url;
}

/**
* Returns the Current URL, stripping it of known FB parameters that should
* not persist.
*
* @return String the current URL
*/
protected function getCurrentUrl() {
$protocol = isset($_SERVER['HTTPS']) &amp;&amp; $_SERVER['HTTPS'] == 'on'
? 'https://'
: 'http://';
$currentUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$parts = parse_url($currentUrl);

// drop known fb params
$query = '';
if (!empty($parts['query'])) {
$params = array();
parse_str($parts['query'], $params);
foreach(self::$DROP_QUERY_PARAMS as $key) {
unset($params[$key]);
}
if (!empty($params)) {
$query = '?' . http_build_query($params, null, '&amp;');
}
}

// use port if non default
$port =
isset($parts['port']) &amp;&amp;
(($protocol === 'http://' &amp;&amp; $parts['port'] !== 80) ||
($protocol === 'https://' &amp;&amp; $parts['port'] !== 443))
? ':' . $parts['port'] : '';

// rebuild
return $protocol . $parts['host'] . $port . $parts['path'] . $query;
}

/**
* Generate a signature for the given params and secret.
*
* @param Array $params the parameters to sign
* @param String $secret the secret to sign with
* @return String the generated signature
*/
protected static function generateSignature($params, $secret) {
// work with sorted data
ksort($params);

// generate the base string
$base_string = '';
foreach($params as $key =&gt; $value) {
$base_string .= $key . '=' . $value;
}
$base_string .= $secret;

return md5($base_string);
}

/**
* Prints to the error log if you aren't in command line mode.
*
* @param String log message
*/
protected static function errorLog($msg) {
// disable error log if we are running in a CLI environment
// @codeCoverageIgnoreStart
if (php_sapi_name() != 'cli') {
error_log($msg);
}
// uncomment this if you want to see the errors on the page
// print 'error_log: '.$msg."\n";
// @codeCoverageIgnoreEnd
}

/**
* Base64 encoding that doesn't need to be urlencode()ed.
* Exactly the same as base64_encode except it uses
* - instead of +
* _ instead of /
*
* @param String base64UrlEncodeded string
*/
protected static function base64UrlDecode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
}

The End Result

Once all the files are in place, go to your Facebook page and check the operation of the new page tab.  Here's the "before like" page from our example:

Screen Shot 2012 01 09 at 9.58.39 AM e1326121232860 Build a Facebook Page that Changes When Like Is Clicked

Facebook page before like button is clicked

 

And after you click the button, the changed experience:

Screen Shot 2012 01 09 at 12.12.27 PM e1326129214147 Build a Facebook Page that Changes When Like Is Clicked

Post-Click Like Page Revealed

 

So what should you put on your pre- and post-click Like pages?  That's up to you.  But one common thing that marketers will tell you is to have an offer of a free podcast, a whitepaper, PDF download, video, or some other "goodie" that the visitor gets for clicking Like.

The ambitious will also have a secondary offer on the Thank You page.  An even better thing that the user can get if they opt into your email list, for example.

Good luck with your own Facebook page, and if you liked this article, would you please leave a comment and share it?  If have any questions or issues, please post in the comments below.

The Periodic Table of SEO Ranking Factors

Posted on: November 10th, 2011 by Skip Shean No Comments

 

SearchEngineLand Periodic Table of SEO condensed large The Periodic Table of SEO Ranking Factors
 

Thanks to Danny at Search Engine Land. Originally posted at The Periodic Table Of SEO Ranking Factors, used with permission

6 Settings On Your Web Accounts You Should Review Now

Posted on: August 21st, 2011 by Skip Shean No Comments

 

If you're like me, you sign up for accounts on websites without sending the Terms of Service to your attorney for review before clicking "OK".  And most of the time there's a clause that allows the website to change their Terms of Service whenever they need to.

But as you sign up for social networks, you can’t forget that you have occasionally sensitive data out there.  I'm not saying, "be paranoid" -- but don't be foolish, either.  Here’s a list of six things to check on in your accounts.
You might be surprised what you’ve agreed to -- by default.

1.  Facebook

Facebook is infamous for its privacy policies -- and for good reason.  All of your friends and family are there, so it easily gives you a false sense of comfort.  That's no accident.

Facebook's lax/extremely open philosophy on its users' privacy has been the subject of news articles in the WSJ, New York Times, and many other publications, so I won't rehash it here.

But one default allows Facebook to use your picture and name in ads that are shown to your FB friends.  This setting makes perfect sense for a company trying to enhance its advertising effectiveness/revenue, but little sense for you.  But really, can you get pissed off at a company that does exactly what you expect them to do based on their past behavior?

It's next to impossible to consider NOT using Facebook -- 700 million users (and counting) are too attractive an audience to ignore.  Manage your inclusion in ads by going to the top right of your screen after login and clicking:  Account --> Account Settings --> Facebook Ads

Facebook e1313779690671 6 Settings On Your Web Accounts You Should Review Now

Also, don't forget to periodically review the list of apps that you’ve authorized to interact with your account (Account --> Account Settings --> Applications).  If you're like me, you'll have a nice little batch of surprises in there waiting for you.

2.  LinkedIn

Unless you tell them otherwise, LinkedIn can use your name and photo in its advertising campaigns.  Their reasons for using your likeness are obvious. Using a familiar name or face in an ad can increase their conversions and the trust a prospective user has in them.

I think that a lot of people would look at it and say, "Hey, I only use the free version -- letting them use my picture and name is fair."  But they didn't make it opt-in, they made it a by-default, opt-out setting.  If you don’t feel like endorsing linkedin.com, uncheck this box. It’s not terribly hard to find, so login and go to: Username > Settings > Account > Manage Social Advertising.

LinkedIn e1313771339207 6 Settings On Your Web Accounts You Should Review Now

3. Twitter

Twitter has a really easy and great API that lots of websites use to make registering and logging in easier.  Everything from Twitter’s own iPhone and Android apps, to Twitpic and blogs use it!  There haven't been many stories of abuse of the API, but managing the websites and applications that have access to your account is easy.  Log into Twitter and go to Settings --> Applications (or just Click Here).

4. Google

Like Twitter, it’s easy to use Google to register or log into other sites.  Go to http://accounts.google.com your account settings to see what websites have access. Your list probably includes harmless things like YouTube, but you might as well be sure.

5. Yahoo

Yahoo keeps track of your recent locations. Review them and make sure there isn’t any suspicious activity on your account by visiting their location management page. It’s kind of creepy to see a list of all the places you’ve been, so maybe clear everything anyways.

6. Gmail

Gmail also tracks your location and can be set to alert you of anything out of the ordinary, including if your account is open at any another locations.

Take a look by logging in and scrolling to the bottom of your Gmail inbox. On the right, click “details” under “Last account activity: # minutes ago.”   It will also let you logout all the other locations.  If you're like me, there will be a few locations here because your iPhone or Android phone will be logged in, along with your iPad and maybe a second PC.