/**
 * Copyright 2012-2013 StackMob
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.stackmob.customcode;

import com.stackmob.core.customcode.CustomCodeMethod;
import com.stackmob.core.rest.ProcessedAPIRequest;
import com.stackmob.core.rest.ResponseToProcess;
import com.stackmob.sdkapi.SDKServiceProvider;

import java.net.HttpURLConnection;
import java.util.*;

import facebook4j.Facebook;
import facebook4j.FacebookException;
import facebook4j.FacebookFactory;
import facebook4j.Friend;
import facebook4j.Post;
import facebook4j.ResponseList;
import facebook4j.conf.ConfigurationBuilder;


import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

public class HelloWorld implements CustomCodeMethod {

  @Override
  public String getMethodName() {
    return "hello_world";
  }

  @Override
  public List<String> getParams() {
    return Arrays.asList("accessToken");
  }

  @Override
  public ResponseToProcess execute (ProcessedAPIRequest request, SDKServiceProvider serviceProvider) {
      Map<String, Object> map = new HashMap<String, Object>();

      String accessToken = "";
      JSONParser parser = new JSONParser();
      try {
          Object obj = parser.parse(request.getBody());
          JSONObject jsonObject = (JSONObject) obj;
          accessToken = (String) jsonObject.get("accessToken");
      } catch (ParseException pe) {

      }

      ConfigurationBuilder cb = new ConfigurationBuilder();
      cb.setDebugEnabled(true)
              .setOAuthAppId("651101234913565")
              .setOAuthAppSecret("9eb8f1ddb07752885ff07e6d76ad7903")
              .setOAuthAccessToken(accessToken);
              
              
      Configuration con = cb.build();
              
      FacebookFactory f = new FacebookFactory(con);

      Facebook facebook = f.getInstance();
      
      ResponseList<Friend> myFriends = null;
      try {
          myFriends = facebook.getFriends();
      }
      catch (Exception e) {

      }
      
      map.put("msg", "hello");


      return new ResponseToProcess(HttpURLConnection.HTTP_OK, map);
  }

}

@@ -1107,16 +1107,54 @@
 uilder;%0A
+import facebook4j.conf.Configuration;%0A
 %0A%0Aimport
@@ -2322,24 +2322,27 @@
       %0A     
+ //
  FacebookFac
@@ -2382,16 +2382,19 @@
 ;%0A%0A     
+ //
  Faceboo
@@ -2435,16 +2435,19 @@
   %0A     
+ //
  Respons
@@ -2479,24 +2479,27 @@
  null;%0A     
+ //
  try %7B%0A     
@@ -2494,24 +2494,27 @@
  try %7B%0A     
+ //
      myFrien
@@ -2546,24 +2546,27 @@
 );%0A     
+ //
  %7D%0A     
  catch (
@@ -2557,16 +2557,19 @@
  %7D%0A     
+ //
  catch (
@@ -2589,16 +2589,19 @@
 %7B%0A%0A     
+ //
  %7D%0A     

Update HelloWorld.java