Parsing Instagram JSON on Apex

Last week I had a challenge of making a API callout to Instagram from Salesforce and then parse the returned JSON content and the mapped the values to become a record for a custom object. Basically each media post and comments becomes a record in Salesforce.

First off you can start by reading this article

According to http://www.json.org:

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. … JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others.

To begin, what I have here is an API request for comments for a particular media or picture I have in Instagram.

Read the rest of this entry »

Javascript Page Redirect on a VF Page

Stumbled upon this issue and found an easy fix.

You have a VF page that you want to redirect a user to a different website, say for OAuth2 authenticate.

window.location.href='https://api.instagram.com/oauth';

This will not work as the browser will complain about Iframe security or Security sandbox violation.

This is because VF page are iframed, to get around this simply use below to redirect, this will redirect the actual page the VF page is iframed into.

window.top.location = 'https://api.instagram.com/oauth';

Preparing for the Advanced Force.com Developer Exam

I just wanted to share that I took the Advanced Force.com Developer exam and passed the first part of the test which is the multiple choice 69 question exam. The exam test your knowledge on advanced topics covering triggers, execution context, visual force pages, standard and custom controllers, running unit test, development lifecycle, data migration tools among others.

You really need to know these topics in detail and the amount of materials to study is quite a lot too. I suggest about 1-2 months to prepare for the exam.

Below are the links to the docs and guides you need read from start to finish.
1. Get the Study Guide to know the full coverage of topics for the exam
2. Download and do the tutorial for Apex Workbook to start
3. Next go over the tutorial Visualforce workbook
4. The two tutorials above should get you started. Next is download the detailed document guide Apex Code Developer’s Guide and the Visualforce Developer’s guide. Its kinda long and requires patience to finish.
5. Also covered is using the Force.com Migration Tool
6. Development Lifecycle
7. Metadata API Guide
8. Apex CheatSheet
9. And another valuable resource Study Notes
10. And ofcourse use flashcards go to StudyBlue.com

That was the resource I used to pass the first part of the exam. I’m just waiting for the programming assignment.

Getting the Google Data Authentication for Force.com working

Just sharing some information which I hope some would find useful.

I’ve been tinkering around with the Google API Toolkit for Force.com.

For starters, these are basically client libraries built on Apex for Force.com that connect to Google API like Google Docs API, Blogger API, Google Calendar API among others.


The method for authentication on the toolkit is built around the AuthSub authentication which as I found out is already deprecated, it is advised to use OAuth 2.0 for authentication & authorization. What this authentication models do is that you authorize your Google Account/Data to be accessed by an external service using a token. The token can be used as is which expires after 24 hours or you can exchange the token for a multisession token which does not expire. Please read up more on this topic from the links above.

I have a related post on how to get the Google Toolkit API installed on your Mac.

Back to the Google API Toolkit, it has a visualforce page with a controller that when accessed, will make token request to Google with a callback URL. However there are some issues when I tried them. I get the following errors.

The site “http://force.com” has not been registered.

Solution here is I had to hardcode the return URL to be capital Force.com on the visualforce page.

Got that to work but the next issue it seems is that there seems to be new kind of restriction for putting Google Data on an iframe. I got the following error.

Refused to display document because display forbidden by X-Frame-Options.

What I had to do is, let the called page load on its own instead of putting it in an iframe. I did this by window.location then the return url.

Resource:
https://groups.google.com/forum/?fromgroups=#!topic/google-contacts-api/H8X8ukHOgFQ

Setting up Force.com Toolkit for Google Docs API on Mac OS X

This guide will help you setup Mac OS X Mountain Lion for the Force.com Toolkit for Google Docs API.

I assume you already have Eclipse and the Force IDE installed. If not you can follow this route first, then come back here to setup the toolkit.

This setup caused me some headache so I’m blogging the steps I did and some troubleshooting. This would be the major guide to follow but going over the first few step to get Subclipse installed requires some troubleshooting.

http://wiki.developerforce.com/page/Google_Data_APIs_Toolkit_Setup

1. First thing you need is to download and add Subclipse plugin so we can download the toolkit hosted on the Google Repository

http://subclipse.tigris.org/servlets/ProjectProcess?pageID=p4wYuA

Adding the plugin won’t work just yet. You’ll get error about missing JavaHL.

2. Subclipse plugin requires JavaHL which you can install via MacPorts.org or via HomeBrew

I went went to the MacPorts route and installed the pkg for Mountain Lion here.

http://subclipse.tigris.org/wiki/JavaHL

3. After you got the Macport installed you can now install JavaHL, but running the following though command

sudo port install subversion-javahlbindings +no_bdb +universal

If you don’t have XCode installed you’ll get some nasty errors, which for my solution I had to update to the latest XCode version 4.4.1. Go to the AppStore and download XCode.

Error: The installed version of Xcode (2.0orlower) is too old to use on the installed OS version. Version 4.1 or later is recommended on Mac OS X 10.8.

Then after XCode install you need to download additional tools. Launch XCode and go under Preferences and choose Downloads and click Install for the Command Line Tools.

Once done you can finally run the command and it would start fetching and installing a bunch of dependency files.

Finally you can go to Eclipse and continue with the initial steps to Checkout.