Jordan M.
Jordan M.

Reputation: 310

How is it possible to use Facebook APIs with Google Chrome?

I'm working on building an extension for Google Chrome that requires a background script to connect to Facebook and make calls to the Graph API and FQL. Unfortunately, I've hit a bit of a roadblock in terms of how to implement this. Chrome uses a built-in CSP to block any inline scripts from running and I haven't had any luck with using JQuery to load the JavaScript SDK for Facebook.

Does anybody have an idea of how to implement this? I can't move forward until I can even load the SDK for Facebook.

Upvotes: 2

Views: 847

Answers (2)

Gaurav Swaroop
Gaurav Swaroop

Reputation: 1221

This is a problem in general if you want to use an external script which updates quickly or is faster than your own server. For security reasons, to prevent cross-site-scripting you need a special permission in your manifest.json file.

"content_security_policy": "script-src 'self' https://connect.facebook.net; object-src 'self'"

You can load external scripts if you specify exactly where you are going to load it from. The CSP cause a lot of problems if you don't know about them. I spent hours trying to figure out what was wrong with my extension before finally getting the answer.

Upvotes: 2

jjNford
jjNford

Reputation: 5270

You need to write the JavaScript in your extension to access the public Facebook API. You will also need to get an OAuth2 token for the user to access their public data. Here are some projects that may help you:

https://github.com/jjNford/html5-storage

https://github.com/jjNford/chrome-extension-socket

https://github.com/jjNford/oauth2-chrome-extension

The first is an HTML5 localStorage wrapper to help you with storing some data in the browser storage (do not store personal data). The second uses the Chrome APIs to create a port between a background page and popup to allow for 2 way communication so you can offload your API requests. The third is a solution to get OAuth2 inside a Chrome Extension - you will need to tweak it to Facebooks specs.

Hope this helps.

Upvotes: 2

Related Questions