Camau i integreiddio facebook gyda Java,en

Facebook Java Integration

Facebook Java Integration

Trosolwg: Social media like facebook, linked-in, twitter are become popular for web marketing. The exposure to social media has a tremendous impact on different fields of marketing, promotion etc. In this article we will discuss facebook integration with java application.








Cyflwyniad: Websites are become an integral part of any business, be it small, medium or big. The web presence is an important aspect to reach the global audience. But only the website is not sufficient to reach the mass audience. For that the social media revolution is very important and it has a cascading effect. Now the social networking sites are also interested to get integrated with other websites as they also need to reach the mass audience. And in the similar way websites need the help of social sites to reach target audience. So, to complement this social sites have exposed their APIs and allows the websites to communicate with them. Facebook provides convenient Graph API to integrate with their site. The Graph API is very powerful and exposes all necessary features required.

The following picture shows the facebook integration with different types of medium like web, ffôn symudol, desktop and many other devices.

Facebook integration cycle

Image1: Facebook integration cycle

model cais Facebook: Now we need to understand the facebook application model to understanding the integration part. The proxy server model used by facebook is the main integration point with the application. Facebook uses REST web services to open its platform to the developers. Datblygwyr yn rhydd i ddefnyddio APIs i integreiddio nodweddion facebook yn eu cais. A'r peth pwysicaf yw bod y datblygwyr yn cael y rhyddid i ddewis unrhyw dechnoleg i ddatblygu eu cais. Felly, gall y llwyfan datblygu cais fod yn unrhyw beth a facebook APIs yno i'w gefnogi. A dylai'r datblygwr ddefnyddio eu cais mewn ffordd fel ei fod yn gallu ymdrin â nifer enfawr o ddata bob dydd.

camau sy'n gweithio yn y model dirprwyol facebook: Yn dilyn yw'r camau a ddefnyddir yn y model dirprwyol facebook

1) Bydd eich cais ar y we yn byw yn eich gwe / gweinydd cais a byddwch yn cofrestru'r URL ganolfan yn cyfrif facebook

2) Pan fydd eich cais yn cael ymweliad yn facebook, bydd yn ffonio eich URL gofrestru ar eich gweinydd

3) Now, Bydd eich cais yn galw APIs facebook angenrheidiol i gael gwybodaeth

4) Eich cais, bydd yn defnyddio ei ddata data a facebook cronfa ddata eu hunain ac yn ei gwneud

5) Ar ôl facebook yma yn dychwelyd cynnyrch eich cais i'r defnyddiwr








Camau i greu cyfrif facebook: Cyn i ni ddechrau integreiddio ein cais gyda APIs facebook, mae angen i ni gofrestru ein cais (gwefan) yn facebook. Ar ôl i chi gofrestru eich cais ar y we yn facebook, Bydd mynediad yn cael ei ddarparu i'r APIs. Dilynwch y camau isod i gofrestru eich cais.

  • Creu eich gwefan a fydd yn defnyddio APIs facebook
  • Creu cyfrif facebook a chofrestru eich cais yno. Yma, bydd yn enw'r wefan.
  • Ar ôl facebook hwn yn creu id cleientiaid ac allwedd gyfrinach ar gyfer y cais ar y we cofrestredig.
  • Defnyddiwch URL galw'n ôl yn ystod cofrestru. Bydd Facebook yn defnyddio'r URL hwn i ailgyfeirio y neges ymateb

Sut i gael lyfrgelloedd facebook:

Cyn i ni yn integreiddio facebook gyda'n cais java mae angen rhywfaint o lyfrgelloedd trydydd parti. These libraries will help us communicate with facebook. Different groups of independent java developers have made efficient facebook libraries for integration purpose.

Gallwch wirio http://code.google.com/p/facebook-java-api/ to get details. These libraries are compatible with Java SE 5 ac uwch.

Download the following JARS

  • http://facebook-java-api.googlecode.com/files/facebook-java-api-1.7.2.jar
  • http://facebook-java-api.googlecode.com/files/json-1.0.jar
  • http://facebook-java-api.googlecode.com/files/facebook-util-1.7.2.jar

If you are using Java application server on top of Java SE 5, then you need to download the following JARs

  • http://facebook-java-api.googlecode.com/files/jaxb-api-2.1.jar
  • http://facebook-java-api.googlecode.com/files/jaxb-impl-2.1.jar
  • http://facebook-java-api.googlecode.com/files/jsr173-api-1.0.jar

You do not need the above three JARs if you are using Java SE 6 or later.

After downloading these JARs, you need to incorporate them in your application. These JARs will provide you API access for different purpose.








Following sample code shows the integration part.

Listing1: Sample showing integration of facebook API and java

[cod]

package techalpine.com;

java.io.BufferedWriter mewnforio;

import java.io.File;

java.io.FileWriter mewnforio;

java.io.IOException mewnforio;

import net.sf.json.JSONArray;

import net.sf.json.JSONObject;

mewnforio facebook4j.Facebook;

facebook4j.FacebookException mewnforio;

mewnforio facebook4j.FacebookFactory;

mewnforio facebook4j.Post;

mewnforio facebook4j.ResponseList;

facebook4j.conf.Configuration mewnforio;

mewnforio facebook4j.conf.ConfigurationBuilder;

public class FacebookImpl {

gwag statig gyhoeddus prif(Llinyn[] args) taflu FacebookException

{

// Make the configuration builder

ConfigurationBuilder confBuilder = new ConfigurationBuilder();

confBuilder.setDebugEnabled(yn wir);

// Set application id, secret key and access token

confBuilder.setOAuthAppId(“8282887”);

confBuilder.setOAuthAppSecret(“c3jhdhjhuh”);

confBuilder.setOAuthAccessToken(“2jskjdbjbdjb”);

// Set permission

confBuilder.setOAuthPermissions(“email,publish_stream, id, enw, first_name, last_name, generig”);

confBuilder.setUseSSL(yn wir);

confBuilder.setJSONStoreEnabled(yn wir);

// Create configuration object

Configuration configuration = confBuilder.build();

// Create facebook instance

FacebookFactory ff = FacebookFactory newydd(ffurfweddiad);

Facebook facebook = ff.getInstance();

roi cynnig ar {

// Get facebook posts

Llinynnol canlyniadau = getFacebookPostes(facebook);

String responce = stringToJson(results);

// Create file and write to the file

file Ffeil = Ffeil newydd(“C:\\Facebook\File\test.txt”);

os (!file.exists())

{

file.createNewFile();

FileWriter FW = FileWriter newydd(file.getAbsoluteFile());

BufferedWriter bw = BufferedWriter newydd(FW);

bw.write(results);

bw.close();

System.out.println(“Writing complete”);

}

} dal (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

getFacebookPostes Llinynnol statig cyhoeddus(Facebook facebook) taflu FacebookException {

// Get posts for a particular search

ResponseList<Post> results = facebook.getPosts(“Reebok”);

return results.toString();

}

cyhoeddus stringToJson Llinynnol statig(data Llinynnol)

{

// Create JSON object

JSONObject jsonObject = JSONObject.fromObject(data);

JSONArray message = (JSONArray) jsonObject.get(“message”);

System.out.println(“Neges : “+message);

return “Done”;

}

}

[/cod]

Facebook Markup Language (FBML): Apart from using facebook REST web service there are another option available to the developers. Facebook Markup Language (FBML) is another powerful offering from facebook community to support application development. Using this markup language developer can easily integrate their application without putting much effort.








Following is a sample code

Listing2: Sample code showing FBML

[cod]

<%@ page language=”java”

contentType=”text/html; charset=UTF-8″

pageEncoding=”UTF-8″

%>

<strong>Myfacebook test page/strong>

<div>

<fb:profile-pic uid=”logged_in_user”

size=”medium”

linked=”yn wir” /><br>

<fb:name uid=”logged_in_user”

use_you=”false”

linked=”yn wir”

capitalize=”yn wir” />,

Use the most popular facebook apps

</div>

[/cod]

Apart from FBML, there are other utilities available for Ajax like effects. There is facebook query language (FBQL) which can be used for searching. All these can be used together and it will help us to make a complex application as per our requirement.

Casgliad: There are many social networking websites available but facebook is most popular. And we have also seen that there are many different applications built on top of facebook APIs. There are also third party libraries available which can be used by java applications to interact with facebook. Felly dod i'r casgliad ein trafodaeth, we can say that social media integration is a new dimension in developer’s world and we should explore it as much as possible.

 

============================================= ============================================== Buy best TechAlpine Books on Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share