Exemplo n.º 1
0
  public boolean getBeepleImages() {
    currentToken = AccessToken.getCurrentAccessToken();
    if (currentToken != null) {
      GraphRequest request =
          GraphRequest.newGraphPathRequest(
              currentToken,
              "/10150428845566781/photos",
              new GraphRequest.Callback() {
                @Override
                public void onCompleted(GraphResponse response) {
                  JSONObject data = response.getJSONObject();
                  try {
                    String newestImage = data.getJSONArray("data").getJSONObject(0).getString("id");
                    getImage(newestImage);
                    Log.d(TAG, newestImage);
                  } catch (org.json.JSONException e) {
                    Log.e(TAG, e.toString());
                  }
                }
              });

      request.executeAsync();
      return true;
    } else {
      Log.d(TAG, "Current access token does not exist");
      return false;
    }
  }
Exemplo n.º 2
0
  // Note that this method makes a synchronous Graph API call, so should not be called from the
  // main thread.
  private static JSONObject getAppSettingsQueryResponse(String applicationId) {
    Bundle appSettingsParams = new Bundle();
    appSettingsParams.putString(APPLICATION_FIELDS, TextUtils.join(",", APP_SETTING_FIELDS));

    GraphRequest request = GraphRequest.newGraphPathRequest(null, applicationId, null);
    request.setSkipClientToken(true);
    request.setParameters(appSettingsParams);

    return request.executeAndWait().getJSONObject();
  }
  private void makeGraphCall() {
    // If you're using the paging URLs they will be URLEncoded, let's decode them.
    try {
      graphPath = URLDecoder.decode(graphPath, "UTF-8");
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }

    String[] urlParts = graphPath.split("\\?");
    String graphAction = urlParts[0];
    GraphRequest graphRequest =
        GraphRequest.newGraphPathRequest(
            AccessToken.getCurrentAccessToken(),
            graphAction,
            new GraphRequest.Callback() {
              @Override
              public void onCompleted(GraphResponse response) {
                if (graphContext != null) {
                  if (response.getError() != null) {
                    graphContext.error(getFacebookRequestErrorResponse(response.getError()));
                  } else {
                    graphContext.success(response.getJSONObject());
                  }
                  graphPath = null;
                  graphContext = null;
                }
              }
            });

    Bundle params = graphRequest.getParameters();

    if (urlParts.length > 1) {
      String[] queries = urlParts[1].split("&");

      for (String query : queries) {
        int splitPoint = query.indexOf("=");
        if (splitPoint > 0) {
          String key = query.substring(0, splitPoint);
          String value = query.substring(splitPoint + 1, query.length());
          params.putString(key, value);
        }
      }
    }

    graphRequest.setParameters(params);
    graphRequest.executeAsync();
  }
Exemplo n.º 4
0
  private void getImage(String id) {

    if (android.os.Build.VERSION.SDK_INT > 9) {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
    }

    GraphRequest request =
        GraphRequest.newGraphPathRequest(
            currentToken,
            "/" + id,
            new GraphRequest.Callback() {
              @Override
              public void onCompleted(GraphResponse response) {
                JSONObject data = response.getJSONObject();
                try {
                  JSONArray images = data.getJSONArray("images");
                  for (int idx = 0; idx < images.length(); idx++) {
                    String height = images.getJSONObject(idx).getString("height");
                    String width = images.getJSONObject(idx).getString("width");
                    if (height != null && width != null) {
                      if (height.equals("320") || width.equals("320")) {
                        URL url = new URL(images.getJSONObject(idx).getString("source"));
                        setCurrentBitmap(
                            BitmapFactory.decodeStream(url.openConnection().getInputStream()));
                      }
                    } else {
                      Log.d(TAG, "Null value for height or width of image");
                    }
                  }
                } catch (org.json.JSONException | java.io.IOException e) {
                  Log.e(TAG, e.toString());
                }
              }
            });

    Bundle parameters = new Bundle();
    parameters.putString("fields", "images");
    request.setParameters(parameters);
    request.executeAsync();
  }
Exemplo n.º 5
0
    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
      final Album album = mAlbums.get(position);

      holder.mAlbumNameView.setText(album.getName());

      String facebookId = null;
      try {
        facebookId = album.getAuthor().fetchIfNeeded().getString("facebookId");

        ParseQuery<Photo> query = ParseQuery.getQuery(Photo.class);
        query.whereEqualTo("originAlbum", album);
        query.findInBackground(
            new FindCallback<Photo>() {
              public void done(List<Photo> scoreList, ParseException e) {
                if (e == null) {
                  if (!scoreList.isEmpty()) {
                    int width = holder.mThumbnailView.getWidth();
                    int height = holder.mThumbnailView.getHeight();
                    mBitmapDownloader.queueUrl(
                        holder.mThumbnailView,
                        scoreList.get(0).getImage().getUrl(),
                        new Size(width, height));
                  }
                } else {
                  e.printStackTrace();
                }
              }
            });

        AccessToken accessToken = AccessToken.getCurrentAccessToken();
        GraphRequest request =
            GraphRequest.newGraphPathRequest(
                accessToken,
                "/" + facebookId,
                new GraphRequest.Callback() {
                  @Override
                  public void onCompleted(GraphResponse response) {
                    JSONObject result = response.getJSONObject();
                    try {
                      String name = result.getString("name");
                      String pictureUrl =
                          result.getJSONObject("picture").getJSONObject("data").getString("url");
                      holder.mAuthorNameView.setText(name);
                      holder.mNumberCollaboratorsView.setText(
                          String.valueOf(album.getNumberOfCollaborators()));

                      int width = holder.mAuthorPictureView.getWidth();
                      int height = holder.mAuthorPictureView.getHeight();

                      mBitmapDownloader.queueUrl(
                          holder.mAuthorPictureView, pictureUrl, new Size(width, height));
                    } catch (JSONException e) {
                      e.printStackTrace();
                    }
                  }
                });

        Bundle parameters = new Bundle();
        parameters.putString("fields", "name,picture");
        request.setParameters(parameters);
        request.executeAsync();
      } catch (ParseException e) {
        e.printStackTrace();
      }
    }