I working with restFB for calling FaceBook Graph api to login, get posts and etc of users.
Created an app in developers account of Facebook.
Tried to call user details, with token generated here,
https://developers.facebook.com/tools/explorer?method=GET&path=8560751784547897&version=v2.8
For Example: accessToken from the above url provides = EAA....F
I am able to get all user details, when I am hitting url in browser as follows,
https://graph.facebook.com/v2.8/me?fields=id,name,email,birthday?access_token=EAA....f
I am getting following response in browser,
{
"id": "1127949",
"name": "youtr name",
"email": "youmail\u0040gmail.com"
"birthday": "10/27/1998"
}
I used following code to generate accesstoken dynamically,
StringBuffer callbackURLbuffer = request.getRequestURL();
int index = callbackURLbuffer.lastIndexOf("/");
callbackURLbuffer.replace(index, callbackURLbuffer.length(), "").append("/callback");
callbackURL = URLEncoder.encode(callbackURLbuffer.toString(), "UTF-8");
String authURL = "https://graph.facebook.com/oauth/authorize?client_id="
+ facebookAppId
+ "&redirect_uri="
+ callbackURL
+ "&scope=user_about_me,"
+ "user_actions.books,user_actions.fitness,user_actions.music,user_actions.news,user_actions.video,user_activities,user_birthday,user_education_history,"
+ "user_events,user_photos,user_friends,user_games_activity,user_groups,user_hometown,user_interests,user_likes,user_location,user_photos,user_relationship_details,"
+ "user_relationships,user_religion_politics,user_status,user_tagged_places,user_videos,user_website,user_work_history,ads_management,ads_read,email,"
+ "manage_notifications,manage_pages,publish_actions,read_friendlists,read_insights,read_mailbox,read_page_mailboxes,read_stream,rsvp_event";
In my callbackURL servlet, I am getting accessToken with code
value, as follows,
StringBuffer redirectURLbuffer = request.getRequestURL();
int index = redirectURLbuffer.lastIndexOf("/");
redirectURLbuffer.replace(index, redirectURLbuffer.length(), "").append("/callback");
redirectURL = URLEncoder.encode(redirectURLbuffer.toString(), "UTF-8");
code = request.getParameter("code");
if(null!=code) {
accessURL = "https://graph.facebook.com/oauth/access_token?client_id=" + facebookAppId +
"&redirect_uri=" + redirectURL + "&client_secret=" + facebookAppSecret + "&code=" + code;
webContent = getWebContentFromURL(accessURL);
accessToken = getAccessTokenFromWebContent(webContent);
other functions used for this above code,
private static String getWebContentFromURL(String webnames) {
try {
URL url = new URL(webnames);
URLConnection urlc = url.openConnection();
//BufferedInputStream buffer = new BufferedInputStream(urlc.getInputStream());
BufferedReader buffer = new BufferedReader(new InputStreamReader(urlc.getInputStream(), "UTF8"));
StringBuffer builder = new StringBuffer();
int byteRead;
while ((byteRead = buffer.read()) != -1)
builder.append((char) byteRead);
buffer.close();
String text=builder.toString();
return text;
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
And,
private static String getAccessTokenFromWebContent (String webContent) {
String accessToken = null;
int s = webContent.indexOf("access_token=") + ("access_token=".length());
int e = webContent.indexOf("&");
accessToken = webContent.substring(s, e);
return accessToken;
}
Lets say this accessToken = EAA....2
If I call the below url with this Token,
https://graph.facebook.com/v2.8/me?fields=id,name,email,birthday&access_token=EAA....2
I am getting following response,
{
"id": "1127949",
"name": "youtr name",
"email": "youmail\u0040gmail.com"
}
If I hit following url, with bio feild, I got error msg in json as follows,
{
"error": {
"message": "(#12) bio field is deprecated for versions v2.8 and higher",
"type": "OAuthException",
"code": 12,
"fbtrace_id": "ARkoFJVP/Jk"
}
}
can some one say why this is happening for me.