0
public class facebookuser{
    public String id;   //115020323424341
    public String name; //XXXX
    public cls_picture picture;
    public String birthday; //09/12/1990
    public String about;    //I beleive
    public class cls_picture {
        public cls_data data;
    }
    public class cls_data {
        public boolean is_silhouette;
        public String url; 
    }
    public static facebookuser parse(String json){
        return (facebookuser) System.JSON.deserialize(json, facebookuser.class);
    }
}

global class facebook_call
{
     public static String getownprofile(String token)
     {
            Boolean flag =false;
            Http http =new Http();
            HttpRequest req =new HttpRequest();
            req.setEndpoint('https://graph.facebook.com/me?fields=id,name,picture,birthday,about&access_token='+token);
            req.setmethod('POST');
            HttpResponse res = http.send(req);             
           facebookuser objfacebookuser = new facebookuser();
           objfacebookuser=facebookuser.parse(res.getBody());
    } 

objfacebookuser is Null. why ? Do i need to set properties in default constructor ? Then How ?

beginner in APEX

 {
  "id": "112344322434",
"name": "XXXXXXXXXXXX",
"birthday": "09/12/1990",
"about": "I beleive.",
"picture": {
"data": {
  "is_silhouette": false,
  "url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/13658929_1039496126116440_8074761312212223685568213_n.jpg?oh=24a1c83a6417dd176bc5c134637a0d1b&oe=58B47A02"
 }
}
}

debug log

16:26:58:430 USER_DEBUG [54]|DEBUG|facebookuser:[about=null, birthday=null, id=null, name=null, picture=null]

  • can you post sample response you got. – Reshma Dec 12 '16 at 10:22
  • { "id": "112344322434", "name": "XXXXXXXXXXXX", "birthday": "09/12/1990", "about": "I beleive.", "picture": { "data": { "is_silhouette": false, "url": "scontent.xx.fbcdn.net/v/t1.0-1/p50x50/…" } } } – Innodel Salesforce Dec 12 '16 at 10:30
  • When I tested parsing with your sample response it worked fine. It parsed well. DEBUG|objfacebookuser facebookuser:[about=I beleive., birthday=09/12/1990, id=112344322434, name=XXXXXXXXXXXX, picture=cls_picture:[data=cls_data:[is_silhouette=false, url=scontent.xx.fbcdn.net/v/t1.0-1/p50x50/…]]] – Reshma Dec 12 '16 at 10:46
  • That Method is static . Is it the reason for being Null ?. Heard about static that It runs in diffenrent context, – Innodel Salesforce Dec 12 '16 at 10:49
  • 16:26:58:430 USER_DEBUG [54]|DEBUG|facebookuser:[about=null, birthday=null, id=null, name=null, picture=null] – Innodel Salesforce Dec 12 '16 at 10:59
2

Make the request as GET Method It will return perfect output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.