private static Twitter getTwitter(HandlerContext handlerContext) {
    Twitter res = (Twitter) handlerContext.get("twitter");
    if (res == null) {
      TwitterLinksHandlerConfig twitterLinksHandlerConfig =
          (TwitterLinksHandlerConfig) handlerContext.getHandlerConfig();
      ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
      configurationBuilder
          .setDebugEnabled(true)
          .setOAuthConsumerKey(twitterLinksHandlerConfig.getOauthConsumerKey());
      configurationBuilder.setOAuthConsumerSecret(
          twitterLinksHandlerConfig.getOauthConsumerSecret());
      configurationBuilder.setOAuthAccessToken(twitterLinksHandlerConfig.getOauthAccessToken());
      configurationBuilder.setOAuthAccessTokenSecret(
          twitterLinksHandlerConfig.getOauthAccessTokenSecret());
      TwitterFactory twitterFactory = new TwitterFactory(configurationBuilder.build());
      res = twitterFactory.getInstance();

      handlerContext.put("twitter", res);
    }
    return res;
  }
Example #2
0
  private Customsearch getCustomsearch(HandlerContext handlerContext) {
    Customsearch res = (Customsearch) handlerContext.get("customsearch");
    if (res == null) {
      Customsearch.Builder customSearchBuilder;
      try {
        customSearchBuilder =
            new Customsearch.Builder(
                GoogleNetHttpTransport.newTrustedTransport(), JSON_FACTORY, null);
        customSearchBuilder.setApplicationName(APPLICATION_NAME);
        String key = ((PixGameHandlerConfig) handlerContext.getHandlerConfig()).getKey();
        customSearchBuilder.setCustomsearchRequestInitializer(
            new CustomsearchRequestInitializer(key));
        res = customSearchBuilder.build();

        handlerContext.put("customsearch", res);
      } catch (Exception e) {
        Log.e(
            TAG,
            "PixGameHandler Could not initialize! PixGameHandler will not work until this problem is resolved",
            e);
      }
    }
    return res;
  }