Despite the commotion about Jobs’s death, many probably don’t know about the death of Dennis Ritchie (even that being in second on Twitter Worldwide Trend Topics while I was writing this post). Yeah, who the hell is Dennis Ritchie? I had no idea either, but his legacy is much bigger than Jobs’s.
2011-10-13
Fuck off death reaper! Dennis Ritchie too?!
2011-10-05
[drops.log]: Life follows...
I was thinking in to entitle this post as “Apple loses jobs even no one was fired”. But I guess the main thing here is: life follows.Steve Jobs passed away but that means little. Better products weren’t going to stop of show up. Apple is not going to die tomorrow.
2011-09-30
[drops.log]: An inverse path, from photo to album
Wow! I’ve been absent since last week. My logs didn’t increase much in the while. I keep groping the Facebook Graph API with the restFB java wrapper.
//posts is a Post list retrived from a user's feed Post post = posts.get(i); if(post.getType() != null && post.getType().equals("photo")) { //Got a photo if(post.getCaption() != null) { //it is from a new album //this regex compilation could be static final String ALBUM_REGEX = "(?<=set=a\\.)\\d+"; Pattern pattern = Pattern.compile(ALBUM_REGEX); Matcher matcher = pattern.matcher(post.getLink()); if(matcher.find()) { String albumId = matcher.group(); Connection< Photo > photos = fbcClient.fetchConnection(albumId + "/photos", Photo.class); for(Photo photo : photos.getData()) { //do your job with the photos } } } }
2011-09-24
[drops.log]: To pay attention usually pays the effort
That title is a bit vague but can get handy. I commented I got stuck with Facebook Real-time Updates API. The problem was incompatibility between my subscription and user authorization. I subscribed to users feed, but never asked them (myself in the case) for the auth to read their feeds. Of course facebook would never pass me content users never allowed me to get even with a offline access token. By the way, I haven't tried yet, but I am pretty sure you will need one to handle updates processing since the updates are mere announces, no content is delivered.
2011-09-23
[drops.log]: Facebook in Java
I started to do a small piece of code to interact with facebook. I spent some days wondering why the hell my application wasn’t working. The case is bad documentation on Facebook developers page. They say you should pass the authorization code and your app secret to the Graph API token endpoint from an URL like this:
public class FacebookAuthorizationFilter implements Filter { public static final String AUTH_URL_BASE = "https://www.facebook.com/dialog/oauth?client_id=%s&redirect_uri=%s&scope=%s"; public static final String ACCESS_TOKEN_URL_BASE = "https://graph.facebook.com/oauth/access_token?client_id=%s&redirect_uri=%s&client_secret=%s&code=%s"; @Override public void init(FilterConfig filterConfig) throws ServletException { /*init code*/ } @Override public void destroy() { /*destroy code*/ } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; String code = request.getParameter(MyConstants.CODE_PARAM_KEY); String accessToken = request.getParameter(MyConstants.ACCESS_TOKEN_PARAM_KEY); if(accessToken != null) { //there is one already let the application follow usually chain.doFilter(req, resp); return; }else { if(code == null) { //ask for authorization from facebook resp.sendRedirect(String.format(AUTH_URL_BASE, this.appKey, this.redirectURI, this.scope)); } else { //already authorized, fetch the access_code accessToken = retriveAccessToken(code); //save the access_token req.getSession().setAttribute(MyConstants.ACCESS_TOKEN_KEY, accessToken); chain.doFilter(req, resp); } } } /** * Retrieves the content of the page with the access_code token * @param code the code parameter passed to the redirect_uri from the oath/dialog page * @return The String access_token provided from facebook * @throws IOException */ private String retriveAccessToken(String code) throws IOException { URL url = new URL(String.format(ACCESS_TOKEN_URL_BASE, this.appKey, this.redirectURI, this.appSecret, code)); //TODO: Try to sintetize with CharStreams from guava-libraries ByteArrayOutputStream byteWriter = new ByteArrayOutputStream(); InputStream urlReader = url.openStream(); int r; while((r = urlReader.read()) != -1) { byteWriter.write(r); } String fetchedResult = new String(byteWriter.toByteArray()); String[] fields = fetchedResult.split("&"); //TODO: Make a regex to extract that for(String field : fields) { String[] pair = field.split("="); if(pair.length == 2 && pair[0].equals("access_token")) { return pair[1]; } } throw new RuntimeException(fetchedResult); } }
- Make a filter that asks for the client object or access_token on the session objectc
- If there is no parameter in the session stops the request and redirect to:
- Where scope are the permissions you want
- The redirect_uri is going to work this case and you must to have a filter in the redirect_uri able to get the code parameter (line 30 in the snippet above)
- Fetch the content of the follow URL:
- (Lines 48 to 56 in the snippet above)
- Parse the content to extract the parameters (at least acess_token) (lines 60 to 65 on the snippet above)
- With access_token you can create the actual client object to access facebook data (line 37 on the snippet above)
- Put the object where you can retrieve it (line 35 in the snippet above)
2011-09-20
[drops.log]: Google+ API roadmap (and shortcuts...)
Well, my foreplay with Google+ API, launched past week, was too rush and to practical. Let’s make some notes useful for the next time.
- To work with Google+ API we need the Google Client API to get access to user google account and the Google Plus Service API. Make sure to download both
- We need to get permission from our apps access Google services and data. SO you need to sign in Google API Console
- Create the app by creating a Client ID, providing type of app, hostname address
- Switch to ON the status of the services you will need to access from our app
public class GoogleAuthFilter implements Filter { @Override public void init(FilterConfig arg0) throws ServletException { // TODO Auto-generated method stub } @Override public void destroy() { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; AccessTokenResponse accessToken = (AccessTokenResponse)req.getSession().getAttribute(MyConstants.ACCESS_TOKEN_RESPONCE_KEY); //test to check access credential if(accessToken == null) { String code = req.getParameter(MyConstants.CODE_KEY); if(code == null) { //no code means the user must allow the app access their data AuthorizationRequestUrl authUrl = new GoogleAuthorizationRequestUrl( MyConstants.CLIENT_ID, MyConstants.REDIRECT_URI, MyConstants.GOOGLE_PLUS_SCOPE_URL); resp.sendRedirect(authUrl.build()); } else { //use the code to generate access token accessToken = new GoogleAccessTokenRequest. GoogleAuthorizationCodeGrant( new NetHttpTransport(), new GsonFactory(), MyConstants.CLIENT_ID, MyConstants.CLIENT_SECRET, code, MyConstants.REDIRECT_URI ).execute(); req.getSession().setAttribute(MyConstants.ACCESS_TOKEN_RESPONCE_KEY, accessToken); resp.sendRedirect(MyConstants.SERVLET_PATH); } } chain.doFilter(req, resp); } }
AccessTokenResponse accessToken = (AccessTokenResponse)req.getSession().getAttribute(MyConstants.ACCESS_TOKEN_RESPONCE_KEY); GoogleAccessProtectedResource requestInitializer = new GoogleAccessProtectedResource( accessToken.accessToken, new NetHttpTransport(), new GsonFactory(), MyConstants.CLIENT_ID, MyConstants.CLIENT_SECRET, accessToken.refreshToken); Plus plus = new Plus(new NetHttpTransport(), requestInitializer, new GsonFactory());
String who = req.getParameter(MyConstants.WHO_KEY); who = who == null ? "me" : who; Person me = plus.people.get(who).execute();
- Google API Console: https://code.google.com/apis/console
- Google Client API Downloads Page: http://developers.google.com/+/downloads
- Google API Java Client Developer’s Page (be aware they misleading concerning the versions of Client API wrapper and Service API wrappers, use 1.5.0-beta for the first one and 1.2.1 for the Google+ Service API wrapper): http://code.google.com/p/google-api-java-client/wiki/DeveloperGuide
- Google+ Developers Discussion Group: http://groups.google.com/group/google-plus-developers
- Google Client API Javadoc: http://javadoc.google-api-java-client.googlecode.com/hg/1.5.0-beta/index.html
- Google+ API Javadoc: http://javadoc.google-api-java-client.googlecode.com/hg/apis/plus/v1/index.html
- Bugs, issues and Features requests of Google+ platform: http://code.google.com/p/google-plus-platform/issues/list
- Bugs, issues and Features requests for the JAVA wrappers: http://code.google.com/p/google-api-java-client/issues
- Authorized Access Sites, Apps and Services configuration page: https://accounts.google.com/b/0/IssuedAuthSubTokens
[drops.log]:More, more, more, plus... Google+
Not long ago I dropped something about the Google+ API release. Well, they do not let any grumpy comments (like mine) get cold. They just released the Google+ Hangout API. Well, of course I need to take a look, make some tests, but I have to much to do right now (Anyone could help with Facebook Real-time Updates on app hosted in Google Appengine?).
2011-09-19
[drops.log]: FHS, where to install stuff?
I have been reading the the Filesystem Hiearchy Standart (FHS) documentation. As I was reading I was checking the contents o different Linux boxes I have access to (debian, ubuntu and CentOS). What got me confused was about the /opt. Since google chrome is installed in the /opt/google/chrome as recommended but besides that /opt directories were empty.
2011-09-17
[drops.log]: Google+ API... First Impressions
I tried three times write this drop, but they just become too long. I guess after I am going to write a roadmap + shortcuts to make the first app accessing Google+.
2011-09-16
[drops.log]:A definitive future to AI
I am going to start the Stanford AI course in October. I like AI concepts. People think about Terminator when they think about AI and that is plain dummy, I guess. But after this study hint, let’s go to what was in my mind.
2011-09-14
[drops.log]:Why innovate when you can copy?
What has Facebook done to fight its direct competitors, Twitter and Google+ ? They definitely aren’t standing still. For instance, they enhanced their share feature. It is not as easy and practical as Google+ however. They have launched a Subscribe option. Basically you can provide a Subscribe button on your profile and let people follow you. That is the Twitter main behavior, for sure. So, instead of making innovations are they replicating their competitors’ best features and concepts? That is at least fair keeping in mind how much Google+ copied from them.
2011-09-12
[drops.log]: Facebook, Pidgin, OpenID, and other chat frustrations
I started to use the OpenID from Google to access my facebook. That make less loginand password digitation. What frustates me is only initial facebook page can use it to login. If I access from a e-mail they send me that doesn’t work.
2011-09-05
Preface: drops.log
I have more comments than real posts and etc, but since I still don’t started the “Very basics” series I guess my comments could be something for the blog. So, I am going to share small comments, opnions, even code samples here. They are small drops I am going to “log” on the blog. Even though my English sucks I am going to do it in this language.
2011-07-01
Google+ : "MAIS" uma tentativa social do Google
O Google+ saiu e já tem gente achando um barato, gente cautelosa, e claro, gente jogando pedra. Eu particularmente não estava tão empolgado com algo da Google desde que vi o Social Graph API, e provavelmente só vou ficar mais entusiasmado com o Google Wallet. Nesse post vamos dar duas respostas para as seguintes perguntas:
- Pra que serve o Google+ ?
- É mais uma tentativa da Google para a dominação mundial?
Mas a recomendação do dia é você entrar no Google+. Pode ser que ele não desbanque o Facebook ou o Twitter, mas ele com certeza vai aposentar o Orkut.