Example #1
0
 @Ignore("I haven't found yet a way to oauth using swing application")
 @Test
 public void can_call_facebook() throws IOException {
   Facebook facebook = new FacebookBuilder().withApiKey().build();
   AlbumsResponse response = facebook.call(new AlbumsRequest());
   assertThat(response).isNotNull();
 }
Example #2
0
 @SuppressLint("SimpleDateFormat")
 public void getCommunityInformation() {
   JSONArray jArr = null;
   JSONArray jArr2 = null;
   String jsonuser = null;
   String fql =
       "SELECT updated_time, message, attachment FROM stream WHERE source_id =228398190627075";
   Bundle parameters = new Bundle();
   parameters.putString("format", "json");
   parameters.putString("query", fql);
   parameters.putString("method", "fql.query");
   parameters.putString("access_token", getAccessToken());
   JSONObject JOmessage = null;
   JSONObject JOmessage2 = null;
   try {
     jsonuser = "******"data\":" + facebook.request(parameters) + "}";
     JSONObject JObj = new JSONObject(jsonuser);
     jArr = JObj.getJSONArray("data");
     strPic = new String[jArr.length()];
     strCmd = new String[jArr.length()];
     strDte = new String[jArr.length()];
     for (int inI = 0; inI < jArr.length(); inI++) {
       System.out.println("" + inI);
       JOmessage = jArr.getJSONObject(inI);
       strMessage = JOmessage.getString("message");
       strDate = JOmessage.getString("updated_time");
       long lngTimeStamp = Long.valueOf(strDate);
       Date dteGetDate = new Date(lngTimeStamp * 1000L);
       SimpleDateFormat sdfTimeFormatter = new SimpleDateFormat("dd-MM-yyyy  hh:mm aa");
       String strGetTime = sdfTimeFormatter.format(dteGetDate);
       Log.i(SharePicMain.TAG, "UpdateCheckService : DATE=" + strGetTime);
       JSONObject JOattachment = JOmessage.getJSONObject("attachment");
       if (JOattachment.getJSONArray("media") != null) {
         jArr2 = JOattachment.getJSONArray("media");
         JOmessage2 = jArr2.getJSONObject(0);
         strSrc = JOmessage2.getString("src");
       }
       strCmd[inI] = ("\t" + strMessage);
       strDte[inI] = ("\n\tDate :" + strGetTime + "\n");
       strPic[inI] = strSrc;
       strMArListImageurls.add(strPic[inI]);
       strMArlistComments.add(strCmd[inI]);
       strMArlistDate.add(strDte[inI]);
       strMarListCommentsdate.add(strCmd[inI] + "" + strDte[inI]);
     }
   } catch (MalformedURLException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (JSONException e) {
     e.printStackTrace();
   }
 }
    @Override
    public void run() {
      while (provider.isRunning()) {
        ResponseList<Post> postResponseList;
        try {
          postResponseList = client.getFeed(id);

          Set<Post> update = Sets.newHashSet(postResponseList);
          Set<Post> repeats = Sets.intersection(priorPollResult, Sets.newHashSet(update));
          Set<Post> entrySet = Sets.difference(update, repeats);
          LOGGER.debug(
              this.id
                  + " response: "
                  + update.size()
                  + " previous: "
                  + repeats.size()
                  + " new: "
                  + entrySet.size());
          for (Post item : entrySet) {
            String json = DataObjectFactory.getRawJSON(item);
            org.apache.streams.facebook.Post post =
                mapper.readValue(json, org.apache.streams.facebook.Post.class);
            try {
              lock.readLock().lock();
              ComponentUtils.offerUntilSuccess(new StreamsDatum(post), providerQueue);
              countersCurrent.incrementAttempt();
            } finally {
              lock.readLock().unlock();
            }
          }
          priorPollResult = update;
        } catch (Exception e) {
          e.printStackTrace();
        } finally {
          try {
            Thread.sleep(configuration.getPollIntervalMillis());
          } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
          }
        }
      }
    }
  @Override
  public void startStream() {

    client = getFacebookClient();

    if (configuration.getInfo() != null && configuration.getInfo().size() > 0) {
      for (String id : configuration.getInfo()) {
        executor.submit(new FacebookFeedPollingTask(this, id));
      }
      running.set(true);
    } else {
      try {
        String id = client.getMe().getId();
        executor.submit(new FacebookFeedPollingTask(this, id));
        running.set(true);
      } catch (FacebookException e) {
        LOGGER.error(e.getMessage());
        running.set(false);
      }
    }
  }
 @Test
 public void shouldExtractHisEmail() {
   String email =
       Facebook.extractEmail("profile : { email : \"[email protected]\" }");
   assertEquals("*****@*****.**", email);
 }
 public static boolean restore(Facebook session, Context context) {
   SharedPreferences savedSession = context.getSharedPreferences(KEY, Context.MODE_PRIVATE);
   session.setAccessToken(savedSession.getString(TOKEN, null));
   session.setAccessExpires(savedSession.getLong(EXPIRES, 0));
   return session.isSessionValid();
 }
 public static boolean save(Facebook session, Context context) {
   Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
   editor.putString(TOKEN, session.getAccessToken());
   editor.putLong(EXPIRES, session.getAccessExpires());
   return editor.commit();
 }
Example #8
0
 protected final java.util.Date getJavaDate(String name) {
   return Facebook.parseDate(json.getString(name));
 }