Monday, June 18, 2012

Getting an App Access Token using the C# Facebook SDK

Getting an App Access Token using the C# Facebook SDK version 6.0

So there I was trying to figure out how to get the app access token using the C# Facebook SDK. I read about how to get one from Facebook's documentation, but it said something about extracting the value from the query string. But that didn't make too much sense. So I played around with some code and got it to work.


var fb = new Facebook.FacebookClient();

dynamic tokenInfo = 
  fb.Get(
    String.Format(
      "/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials", 
      appId, 
      appSecret));

var appAccessToken = (string)tokenInfo.access_token;


Yes, that simple. :)

Now with this app access token, I'm able to post on the each user's behalf if they granted me publish stream permissions. But what about if you want to post to a user's page? Well that is something that Facebook didn't make standard.

Here's what Facebook would like you to do.

1. Get a user access token
2. Extend that token to a 60-day token
3. Call /me/accounts and grab the access token from the page

This will be the non-expiring token you can use to publish with to the user's wall.


Happy coding!

Thursday, May 24, 2012

A cypher toes width tune min inning lush woulds flow tuna rounding taryn adds


This one I did quickly so don't punish me!

"A site for those with too many English words floating around in their heads." would translate to "A cypher toes width tune min inning lush woulds flow tuna rounding taryn adds."

For this crazy homophonic fun see: http://www.crockford.com/wrrrld/anguish.html

Some strange sentences!

Just found these sentences (well kinda of in some cases).

My two favorites are the one about Alex Trebek and the one about jukeboxes.

  • DJs flock by when MTV ax quiz prog.
  • Junk MTV quiz graced by fox whelps.
  • Bawds jog, flick quartz, vex nymphs.
  • Waltz, bad nymph, for quick jigs vex!
  • Fox nymphs grab quick-jived waltz.
  • Brick quiz whangs jumpy veldt fox.
  • Bright vixens jump; dozy fowl quack.
  • Quick wafting zephyrs vex bold Jim.
  • Quick zephyrs blow, vexing daft Jim.
  • Sex-charged fop blew my junk TV quiz.
  • How quickly daft jumping zebras vex.
  • Two driven jocks help fax my big quiz.
  • Quick, Baz, get my woven flax jodhpurs!
  • "Now fax quiz Jack! " my brave ghost pled.
  • Five quacking zephyrs jolt my wax bed.
  • Flummoxed by job, kvetching W. zaps Iraq.
  • Cozy sphinx waves quart jug of bad milk.
  • A very bad quack might jinx zippy fowls.
  • Few quips galvanized the mock jury box.
  • Quick brown dogs jump over the lazy fox.
  • The jay, pig, fox, zebra, and my wolves quack!
  • Blowzy red vixens fight for a quick jump.
  • Joaquin Phoenix was gazed by MTV for luck.
  • The quick, brown fox jumps over a lazy dog.
  • A wizard’s job is to vex chumps quickly in fog.
  • Watch "Jeopardy! ", Alex Trebek's fun TV quiz game.
  • Woven silk pyjamas exchanged for blue quartz.
  • Brawny gods just flocked up to quiz and vex him.
  • Adjusting quiver and bow, Zompyc[1] killed the fox.
  • My faxed joke won a pager in the cable TV quiz show.
  • Amazingly few discotheques provide jukeboxes.
  • My girl wove six dozen plaid jackets before she quit.
  • Six big devils from Japan quickly forgot how to waltz.
  • Big July earthquakes confound zany experimental vow.
  • Foxy parsons quiz and cajole the lovably dim wiki-girl.
  • Have a pick: twenty six letters - no forcing a jumbled quiz!
  • Crazy Fredericka bought many very exquisite opal jewels.
  • Sixty zippers were quickly picked from the woven jute bag.
  • A quick movement of the enemy will jeopardize six gunboats.
  • All questions asked by five watch experts amazed the judge.
  • Jack quietly moved up front and seized the big ball of wax.

Can you tell me what these sentences have in common with each other?

Thanks to this lorem ipsum generator tool that led me to this.

Monday, April 23, 2012

12 Miles of Terror! and A MiNi Vacation In Vegas


12 Miles of Terror and AMVIV?

A MiNi Vacation In Vegas (AMVIV) is going to have a fun run to the 12 Miles of Terror in 2012.

The location


Hwy 97 runs between Hwy 93 and Hwy 96 in the western part of Arizona, USA. It's actually just 11 miles long, but 12 sounded more fun when we coined the term.


View Larger Map

Some history


I still remember my first run in my 2003 MINI on that road back in 2003, followed by a MiNi fun-run I organized to incredibly fun (and dangerous as some have found) stretch of pure motoring bliss! It's nice to see both of these events/runs that I started are still going strong.


Here's some threads on some other people organizing their own runs on it after I had introduced them to the 12 miles of terror.


Have fun and be safe everyone!!

Tuesday, April 17, 2012

Facebook login, I don't get session when in IE

The symptoms


I've implemented Facebook login on my website using one of the Facebook Graph API SDKs, all browsers seem to work other than Internet Explorer (IE). In IE, the session doesn't seem to work. Why is that?

The problem


Internet Explorer is very twitchy about storing cookies from 3rd parties. This is what is happening with your site and how Facebook logs in. Since the user is on your domain, IE is simply ignoring your session cookie.

The solution


Simply implement P3P headers in your server's responses. This way IE will think your site is alright and then allow this 3rd party cookie to be stored allowing session to be maintained for the SDK to use.

Here's a couple of articles on how to implement a P3P header.

Happy Coding!

Knowing when someone shared your page

Three major players


I usually focus on the three major players in the social media arena. Facebook, Twitter, and Google+. Sorry to all of the other players like LinkedIn, etc.

How to track who shared your page(s)


On each page where you have the Facebook like, Twitter tweetbox, and Google Plus's +1 button, simply subscribe to the callbacks specific to each environment.




Then in your callback functions, just AJAX whatever you want back to your server for it to store. :)



Happy Coding!

Facebook Access Tokens in a nutshell

Three different types of access tokens


APP access tokens

are used to get information that your app is privileged to access from the Facebook Graph API. And in some cases where publish_stream is granted from an app user, you can use it to post to that user's wall, without needing a USER access token.

USER access tokens

are given to your app and they relate to the permissions a specific app user has granted to your application so you app can act on their behalf when interacting with the Facebook Graph API.

PAGE access tokens

are given to page admins so they can act on behalf of the page. To go from a user access token to a page access token, call /me/accounts using the user access token to get a list of pages they admin along with each pages access tokens.

Useful tips


If you have an access token and you want to know more information about it, lint it at Facebook's URL and access token debugger.

For more information on access tokens see: Facebook's authentication documentation.

Friday, March 30, 2012

Crazy bus driver between Thekkady and Alappuzha



Looks like this is becoming a popular video on YouTube, it's starting to get over 200 views a day now.  At present, it has nearly 5000 views.  :)  I just wish I could have got the camera going earlier, as he was really getting a lot of body roll, unsafely leaning the bus into the oncoming lanes of traffic.

Tuesday, March 27, 2012

Facebook access tokens and offline access deprecation

Uh oh, Facebook's changing things again...

Recently Facebook announced deprecation of offline_access permissions. So the question that is most frequently asked is "How do I get a token I can use when the user is not logged in?"

So, please add this to your FAQ.

How do I get a token for offline access?

Fairly simple. When the user is logged into your app, take their current access token (usually this one expires in an hour or so) and pass it as a query string parameter to a specific URL.

That url is:

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]


Replace [APP_ID], [APP_SECRET] and [EXISTING_ACCESS_TOKEN] with your application values and the current access token, and in the response from Facebook, you will get a 60 day access token.

Why is Facebook making it hard?

In my opinion, I believe it is to reduce the number of spammy apps. Facebook says it's to drive more traffic to your app and also to ensure that your app is relevant and important to the user. I've heard of Facebook also wanting to ensure that the apps become less independent and more dependent on user interaction. Most developers do hope that their app is relevant and useful to the user. And most developers are not trying to spam. However, because of the naughty ones, the rest of us have to suffer who want to do something like making it easier for marketers to schedule posts in advance.

Can I exchange my 60 day access token for a new 60 day access token?

No, sorry you cannot. You can only exchange a valid (meaning current) user access token for an extended one. You cannot extend an already extended access token.

Final thoughts

So with this knowledge, we need to make our apps more engaging and let the user know they will need to visit fairly often. For those apps that do automated work with no user interaction, this means someone will have to manually get a 60 day token (I prefer to use the Facebook Graph API Explorer Tool) and plug it into their application via refreshable settings, as opposed to hard-coded in compiled apps.

Wednesday, March 21, 2012

Tuesday, March 20, 2012

How to use the Graph API to search for places

Facebook has recently updated their documentation on their search* feature. This is exciting news! In this blog I want to show you how simple it is to search for places or locations in a geographical area. All you need to know is the center coordinates of the location to be searched.

* note: Facebook's made it hard to directly link to the information as they have no anchor tag in the long page. Scroll down to the "Search" heading.

To search for places near a geographical location


https://graph.facebook.com/search?q=coffee&type=place&center=37.76,-122.427&distance=1000&access_token=VALID_ACCESS_TOKEN

I believe the distance parameter is in meters, but it is hard to tell because they've left that part undocumented.

To search for objects near a geographical location


https://graph.facebook.com/search?type=location&center=37.76,-122.427&distance=1000&access_token=VALID_ACCESS_TOKEN

What's interesting is you will get check-ins from friends if you're using a user access token for this query. Here's what Facebook says:

In addition, the returned objects will be those in which you or your friend have been tagged, or those objects that were created by you or your friends. There are important behavioral differences in the results depending on the permissions your app has acquired. Please see the documentation for the location_post FQL table for more information.

Happy coding! And as always be nice to your API.


Facebook Graph API undocumented (or poorly documented) properties and connections.

I'm writing this post to shed some light on poorly documented Graph API properties and connections. All comments are welcome and I'll try to update this blog entry with the latest and greatest.


photo.backdated_time

Some information about backdated_time can be found in this stackoverflow question.


user.installed

Appears to be letting us know if the user has installed the current application. You can see this field added by specifically declaring on the Graph API call of `me/friends?fields=installed`. Yet another stackoverflow question led me to this information.


user.email

Can't seem to get the email on the user object? Well, just add `?fields=email` to your Graph API query and you now will get that information.

Thursday, March 15, 2012

AMVIV I, a history

Well, using the power of archive.org's wayback machine, I've pulled the content from an old website no longer under my control. This is content I wrote in 2004 and published on http://www.aminivacationinvegas.com. You will note that the site is not current and it appears that the real place for all things AMVIV is http://www.amviv.com.

Here's the link to my content: http://dominicminicoopers.com/amviv/default.aspx Enjoy the throwback in history!

Localizing the Google +1 button plugin code

Localizing the Google +1 button plugin code was kinda a mystery. The documentation for it was difficult for me to find. So i've written this quick how to localize the Google +1 button plugin code.



The trick to it is to use a little documented window.___gcfg object, setting the 'lang' property to the language of your choice. Please note, you will need to do this prior to the loading of the plusone.js code. If you do it afterwards, then the language you specified will be ignored!!

Here's the list of available languages.

I hope this helps you along your way to making the best possible user experience on your website.
Happy coding!!

Assigning URL for Facebook Comments plugin via JavaScript

How to assign a URL for the Facebook comments plugin dynamically at run-time on the client side using some simple JavaScript.

To set your href parameter for the Facebook Comments plugin, simply add the following code.


* Thanks for the tip on how to use gist from github!

In the above code, please note that I'm using the window.fbAsyncInit. When the Facebook JavaScript SDK is loaded dynamically, Facebook will call this function once the SDK is ready to go.

Also note the use of FB.XFBML.parse(); function. This will tell the SDK to reparse the DOM for any Facebook plugin code. It doesn't matter if the code is HTML5 or XFBML, either way, the Facebook JavaScript SDK is smart enough to find either type and will insert their iframed content.

I hope this helps you along your way to making the best possible user experience on your website.
Happy coding!!

Wednesday, March 14, 2012

Tips and Tricks coming soon for Facebook and Google+ integration

Just an announcement that soon I will be writing blogs on how to integrate website with Google+ as well as Facebook like and comments.