-
-
Save ffr4nz/4c2ea3d43b0d83937a96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The MIT License (MIT) | |
Copyright (c) 2016 sinfonier-project | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. | |
*/ | |
package com.sinfonier.bolts; | |
import facebook4j.Facebook; | |
import facebook4j.FacebookException; | |
import facebook4j.FacebookFactory; | |
import facebook4j.IdNameEntity; | |
import facebook4j.Reading; | |
import facebook4j.User; | |
import facebook4j.auth.AccessToken; | |
public class FacebookBoltffranz extends BaseSinfonierBolt { | |
// Class variables | |
private String APPID; | |
private String APPSECRET; | |
private String ACCESSTOKEN; | |
// Must implement constructor. Do not touch | |
public FacebookBolt(String path) { | |
super(path); | |
} | |
@Override | |
public void userprepare() { | |
// Initialize your DB Connections or non-serializable classes. | |
// This method will be executed once. | |
this.APPID = this.getParam("appid"); | |
this.APPSECRET = this.getParam("appsecret"); | |
this.ACCESSTOKEN = this.getParam("accesstoken"); | |
} | |
@Override | |
public void userexecute() { | |
// TO-DO: Write code here. This method will be called every ingoing tuple | |
Facebook facebook = new FacebookFactory().getInstance(); | |
facebook.setOAuthAppId(this.APPID, this.APPSECRET); | |
facebook.setOAuthAccessToken( | |
new AccessToken(this.ACCESSTOKEN, null)); | |
User user; | |
try { | |
//user = facebook.getMe(); | |
Reading reading = new Reading().fields("interested_in, location, friendlists, friends, relationship_status, education, birthday, email, name, first_name, last_name, likes"); | |
user = facebook.getMe(reading); | |
String nombre = user.getName(); | |
if(!nombre.equals("null")) | |
this.addField("nombre", nombre); | |
else | |
this.addField("nombre", 0); | |
String email=user.getEmail(); | |
if(!email.equals("null")) | |
this.addField("email", email); | |
else | |
this.addField("email", 0); | |
for(int i = 0; i < user.getEducation().size(); i++){ | |
IdNameEntity grado = user.getEducation().get(i).getDegree(); | |
if(grado == null) | |
this.addField("educacion"+i,0); | |
else | |
this.addField("educacion"+i, grado); | |
} | |
String localidad = user.getLocation().getName(); | |
if(!localidad.equals("null")) | |
this.addField("localidad", localidad); | |
else | |
this.addField("localidad", 0); | |
}catch (FacebookException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
this.emit(); // Call emit() always at the end of this method. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment