Kết luận chương 4

Một phần của tài liệu Tiểu luận Thực tập cơ sở chuyên ngành An toàn thông tin: Tìm hiểu và sử dụng Facebook API (Trang 38 - 50)

Xây dựng ứng dụng thành công , đáp ứng cơ bản những yêu cầu đặt ra ban đầu. Có thể thống kê id, message, updated_time của các bài viết trên một trang.

Ưu nhược điểm Ưu điểm

 Tận dụng được cộng đồng mạng xã hội facebook.  Đáp ứng được các yêu cầu nghiệp vụ cần thiết.  Giao diện thân thiện với người dùng.

Nhược điểm

 Tính năng ứng dụng chưa đa dạng.

 Từ năm 2018 Fcaebook siết chặt bảo mật nên các yêu cầu ứng dụng khó khăn hơn vì vậy cha ưthể khai thác hết được thế mạnh của Facebook .

KẾT LUẬN

Bốn chương của chuyên đề đã thể hiện được rằng những mục tiêu đặt ra khi thực hiện chuyên đề đều đã đạt được. Cụ thể:

Chương 1 đã hệ thống lại những kiến thức tổng quan về API. Chương này cũng đã chỉ ra các ưu nhược điểm, các thành phần khi sử dụng API cũng như các loại API phổ biến. Tìm hiểu qua về REST API.

Chương 2 giới thiệu cho chúng ta về GRAPH API cụ thể là Facebook Graph API, cách thức hoạt động cũng như cách sử dụng GRAPH API.

Chương 3 lần lượt làm rõ hơn về một loại API phổ biến hiện nay là API các mạng xã hội. Cùng với đó là đi tìm hiểu sâu về API Facebook , một trong những mạng xã hội lớn nhất thế giới với lượng người dùng khổng lồ.

Trong chương 4, một ứng dụng minh họa về việc sử dụng API Facebook đã được xây dựng thành công. Nó cho phép hệ thống trích xuất thông tin của các bài post của một trang trên Facebook.

Dù vậy, vẫn còn một số vấn đề liên quan đến quyền sử dụng thông tin người dùng chưa thể minh họa triệt để trong chuyên đề này . Ứng dụng chỉ mới dừng lại ở mức đơn giản là sử dụng API Facebook như thế nào, và sử dụng vào việc gì. Kể từ Tháng 3 năm 2018, chính sách về API dành cho các nhà phát triển ứng dụng của Facebook đã có nhiều thay đổi, chuyên đề vẫn chưa thể làm rõ được hết các tiềm năng có thể được khai thác ở Facebook API. Việc giải quyết những điểm tồn tại này cũng chính là hướng phát triển tương lai của chuyên đề.

TÀI LIỆU THAM KHẢO

[1]. Braunstein, Mark L. (26 July 2018). Health Informatics on FHIR: How HL7's New API is Transforming Healthcare. Springer. p. 9. ISBN 978-3-319-93414-3

[2]. sproutsocial.com/insights/ [3]. API wiki :

en.wikipedia.org/wiki/Application_programming_interface#cite_note-Braunstein2018-1 [4]. Parnin, Chris; Treude, Cristoph (May 2011). "Measuring API Documentation on the Web".Web2SE. Retrieved 22 July 2016.

[5]. Đồ án tốt nghiệp ứng dụng facebook của Hoàng Thị Hiền lớp K51CHTTT (ĐH CNTT – ĐH QGHN).

[6]. Facebook Developer Wiki . Nguồn: http://wiki.developers.facebook.com/

[7]. Trang tài liệu của nhà phát triển facebook:

PHỤ LỤC Source Code Project

* index.jsp

<!DOCTYPE html> <html>

<head>

<title>DEMO</title> <meta charset="UTF-8"> </head>

<body> <script>

// This is called with the results from from FB.getLoginStatus().

function statusChangeCallback(response) { console.log('statusChangeCallback'); console.log(response); console.log(response.authResponse.accessToken); //alert(response.authResponse.accessToken); if (response.status === 'connected') { window.location.href='Sign_in_Controller.jsp?access_token='+response.authResponse.acc essToken; } else {

// The person is not logged into your app or we are unable to tell. document.getElementById('status').innerHTML = 'Please log ' + 'into this app.';

} }

// This function is called when someone finishes with the Login // Button. See the onlogin handler attached to it in the sample (adsbygoogle = window.adsbygoogle || []).push({});

// code below.

function checkLoginState() {

FB.getLoginStatus(function(response) { statusChangeCallback(response);

}); }

window.fbAsyncInit = function() { FB.init({

appId : '365789034115218',//ĐIỀN ID CỦA APP VỪA LẤY Ở TRÊN

cookie : true, // enable cookies to allow the server to access // the session

xfbml : true, // parse social plugins on this page version : 'v4.0' // use graph api version 4.0 });

FB.getLoginStatus(function(response) { statusChangeCallback(response);

}); };

// Load the SDK asynchronously (function(d, s, id) {

var js, fjs = d.getElementsByTagName(s)[0];

if (d.getElementById(id)) return; js = d.createElement(s); js.id = id;

js.src = "https://connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs);

}(document, 'script', 'facebook-jssdk'));

// Here we run a very simple test of the Graph API after login is // successful. See statusChangeCallback() for when this call is made. </script>

<fb:login-button scope="public_profile,email" onlogin="checkLoginState();"> </fb:login-button>

<div id="status"> </div>

</body> </html>

*Sing_in_Controller.jsp

<%@page import="com.chillyfacts.com.profile.Profile_Bean"%> <%@page import="com.chillyfacts.com.profile.Profile_Modal"%>

<%@page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html> <head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title>

</head> <body> <%

String access_token=(String)request.getParameter("access_token"); Profile_Modal obj_Profile_Modal=new Profile_Modal();

Profile_Bean obj_Profile_Bean= obj_Profile_Modal.call_me(access_token); obj_Profile_Bean.setAccess_token(access_token);

session.setAttribute("fb_user_session", obj_Profile_Bean); %> (adsbygoogle = window.adsbygoogle || []).push({});

<script type="text/javascript">

window.location.href="Profile_Page.jsp"; </script>

</body> </html>

*Profile_Page.jsp

<%@page import="java.util.Iterator"%>

<%@page import="com.chillyfacts.com.posts.Post_Use_Bean"%> <%@page import="java.util.List"%>

<%@page import="com.chillyfacts.com.posts.Post_Modal"%> <%@page import="com.chillyfacts.com.profile.Profile_Bean"%> <%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html> <head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title>

</head> <body> <% Profile_Bean obj_Profile_Bean=(Profile_Bean)session.getAttribute("fb_user_session"); %> <center> <table border="1"> <tr>

<td colspan="2" align="center"> <h2>Profile Page</h2>

</td> </tr> <tr>

<td align="center">

<img src="<%=obj_Profile_Bean.getProfile_picture() %>"></img><br> Page : <%=obj_Profile_Bean.getUser_name() %><br>

id : <%=obj_Profile_Bean.getId() %><br> </td>

<td> <%

Post_Modal obj_Post_Modal=new Post_Modal(); List<Post_Use_Bean> list_of_posts=

obj_Post_Modal.call_me_to_get_posts(obj_Profile_Bean.getAccess_token()); Iterator<Post_Use_Bean> it_list_of_posts=list_of_posts.iterator();

if(list_of_posts.size()>0){

Post_Use_Bean obj_Post_Use_Bean=new Post_Use_Bean();

while(it_list_of_posts.hasNext()){

obj_Post_Use_Bean=it_list_of_posts.next(); %>

<%=obj_Post_Use_Bean.getUpdated_time() %><br> <hr> <% } } %> </td> </tr> </table> </center> </body> </html>

*Post_Modal.java package com.chillyfacts.com.posts; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONObject;

public class Post_Modal {

public List < Post_Use_Bean > call_me_to_get_posts(String access_token) throws

Exception {

List < Post_Use_Bean > list_posts = new ArrayList < Post_Use_Bean > (); (adsbygoogle = window.adsbygoogle || []).push({});

try {

String url =

"https://graph.facebook.com/v4.0/2388761094527134/feed?fields=message%2Cupdated_time& access_token=" + access_token;

URL obj = new URL(url);

HttpURLConnection con = (HttpURLConnection) obj.openConnection(); // optional default is GET

con.setRequestMethod("GET"); //add request header

con.setRequestProperty("User-Agent", "Mozilla/5.0");

int responseCode = con.getResponseCode();

System.out.println("\nSending 'GET' request to URL : " + url); System.out.println("Response Code : " + responseCode);

BufferedReader in = new BufferedReader(

new InputStreamReader(con.getInputStream())); String inputLine;

StringBuffer response = new StringBuffer();

while ((inputLine = in .readLine()) != null) { response.append(inputLine);

} in .close();

System.out.println(response);

JSONObject data_response = new JSONObject(response.toString()); JSONArray data_array = data_response.getJSONArray("data"); System.out.println(data_array.length());

for (int count = 0; count < data_array.length(); count++) { Post_Use_Bean obj_Post_Use_Bean = new Post_Use_Bean();

try {

obj_Post_Use_Bean.setMessage(data_array.getJSONObject(count).getString("message")); } catch (Exception e) {

obj_Post_Use_Bean.setUpdated_time(data_array.getJSONObject(count).getString("updated_ time"));

obj_Post_Use_Bean.setId(data_array.getJSONObject(count).getString("id")); list_posts.add(obj_Post_Use_Bean);

}

JSONObject data_paging = new

JSONObject(data_response.getJSONObject("paging"));

Post_Use_Bean obj_Post_Use_Bean = new Post_Use_Bean();

obj_Post_Use_Bean.setPaging_next(data_paging.getString("next")); obj_Post_Use_Bean.setPaging_previous(data_paging.getString("previous"));

list_posts.add(obj_Post_Use_Bean); } catch (Exception e) {

System.out.println(e); }

//return list_posts;

return list_posts; } (adsbygoogle = window.adsbygoogle || []).push({});

*Post_Use_Bean.java

package com.chillyfacts.com.posts;

public class Post_Use_Bean {

private String message;

private String updated_time;

private String id;

private String paging_previous;

private String paging_next;

public String getPaging_previous() {

return paging_previous; }

public void setPaging_previous(String paging_previous) {

this.paging_previous = paging_previous; }

public String getPaging_next() {

return paging_next; }

public void setPaging_next(String paging_next) {

this.paging_next = paging_next; }

public String getMessage() {

return message; }

public void setMessage(String message) {

this.message = message; }

public String getUpdated_time() {

return updated_time; }

public void setUpdated_time(String updated_time) {

this.updated_time = updated_time; }

public String getId() {

return id; }

public void setId(String id) {

this.id = id; }

*Profile_Bean.java

package com.chillyfacts.com.profile; (adsbygoogle = window.adsbygoogle || []).push({});

public class Profile_Bean {

private String user_name;

private String profile_picture;

private String id;

private String access_token;

public String getAccess_token() {

return access_token; }

public void setAccess_token(String access_token) {

this.access_token = access_token; }

public String getUser_name() {

return user_name; }

public void setUser_name(String user_name) {

this.user_name = user_name; }

public String getProfile_picture() {

return profile_picture; }

public void setProfile_picture(String profile_picture) {

this.profile_picture = profile_picture; }

public String getId() {

return id; }

public void setId(String id) {

this.id = id; }

*Profile_Modal.java package com.chillyfacts.com.profile; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import org.json.JSONObject; public class Profile_Modal {

public Profile_Bean call_me(String access_token) throws Exception {

String url =

"https://graph.facebook.com/v4.0/2388761094527134/?fields=name%2Cid%2Cpicture%7Burl%7 D&access_token="+access_token;

URL obj = new URL(url);

HttpURLConnection con = (HttpURLConnection) obj.openConnection(); // optional default is GET

con.setRequestMethod("GET"); //add request header

con.setRequestProperty("User-Agent", "Mozilla/5.0"); int responseCode = con.getResponseCode();

System.out.println("\nSending 'GET' request to URL : " + url); System.out.println("Response Code : " + responseCode); (adsbygoogle = window.adsbygoogle || []).push({});

BufferedReader in = new BufferedReader(

new InputStreamReader(con.getInputStream())); String inputLine;

StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) {

response.append(inputLine); }

in.close();

System.out.println(response);

Profile_Bean obj_Profile_Bean=new Profile_Bean();

JSONObject myResponse = new JSONObject(response.toString()); obj_Profile_Bean.setUser_name(myResponse.getString("name")); obj_Profile_Bean.setId(myResponse.getString("id")); JSONObject picture_reponse=myResponse.getJSONObject("picture"); JSONObject data_response=picture_reponse.getJSONObject("data"); System.out.println("URL : "+data_response.getString("url")); obj_Profile_Bean.setProfile_picture(data_response.getString("url")); return obj_Profile_Bean; } }

Một phần của tài liệu Tiểu luận Thực tập cơ sở chuyên ngành An toàn thông tin: Tìm hiểu và sử dụng Facebook API (Trang 38 - 50)