コード例 #1
0
  /**
   * 認証Tokenが有効かどうかをチェックする
   *
   * @throws IOException
   */
  public boolean checkToken() throws IOException {
    // alreay has Token?
    SharedPreferences preference =
        context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
    this.token = preference.getString("token", null);

    if (this.token == null) {
      return false;
    }

    // check Token validated.
    // http://flickr.com/services/rest/?method=flickr.auth.checkToken&auth_token=sdkjlsa983&api_key=987654321&frob=1a2b3c4d5e&api_sig=7f3870be274f6c49b3e31a0c6728957f.
    TreeMap<String, Object> map = new TreeMap<String, Object>();

    map.put(paramApiKey, apiKey);
    map.put(paramMethod, AUTH_CHECK_TOKEN);
    map.put(paramResponseFormat, jsonFormat);
    //		map.put(paramFlob, frob);
    map.put(paramAuthToken, this.token);
    map.put(paramApiSig, makeToken(map));

    RestRequestData request = new RestRequestData();
    request.setUrl(baseUrl);
    request.setPath(servicePath + "/" + restPath + "/");
    request.setQueryParam(map);

    URL url = RestfulLib.makeUrl(request);
    String response = RestfulLib.httpGetRequest(url.toString());
    return parseCheckToken(response);
  }
コード例 #2
0
  /**
   * get flickr flobs
   *
   * @throws IOException
   */
  public void getFlob() throws IOException {

    // (example)
    // http://flickr.com/services/rest/?method=flickr.auth.getFrob&api_key=987654321&api_sig=5f3870be274f6c49b3e31a0c6728957f
    TreeMap<String, Object> map = new TreeMap<String, Object>();

    map.put(paramMethod, AUTH_GET_FLOB);
    map.put(paramApiKey, apiKey);
    map.put(paramResponseFormat, jsonFormat);
    map.put(paramApiSig, makeToken(map));

    RestRequestData request = new RestRequestData();
    request.setUrl(baseUrl);
    request.setPath(servicePath + "/" + restPath + "/");
    request.setQueryParam(map);

    URL url = RestfulLib.makeUrl(request);
    String response = RestfulLib.httpGetRequest(url.toString());
    parseFrob(response);
  }
コード例 #3
0
  /**
   * ファイルをアップロードする
   *
   * @param uri
   * @param listner
   */
  public String upload(String uri, final UploadProgressListner listner) {

    String response = null;

    TreeMap<String, Object> map = new TreeMap<String, Object>();

    map.put(paramApiKey, apiKey);
    map.put(paramResponseFormat, jsonFormat);
    map.put(paramAuthToken, this.token);
    map.put(paramTitle, "");
    map.put(paramIsPublic, "0");
    map.put(paramApiSig, makeToken(map));

    InputStream is = null;
    try {
      //			ParcelFileDescriptor pfd =
      // context.getContentResolver().openFileDescriptor(uriList.get(0), "r");
      //			long size = pfd.getStatSize();
      //			try {
      //				pfd.close();
      //			} catch (IOException e) {
      //				e.printStackTrace();
      //			}

      //			is = context.getContentResolver().openInputStream(uriList.get(0));

      String path = null;
      path = uri;

      map.put(paramPhoto, path);

      RestRequestData request = new RestRequestData();
      request.setUrl(baseUrl);
      request.setPath(servicePath + "/" + uploadPath + "/");
      request.setQueryParam(map);

      response =
          RestfulLib.httpPostRequestMultipart(
              request,
              new ProgressListener() {

                @Override
                public void transferred(long num, long contentLength) {
                  Log.d(LOG_TAG, num + " byte written.");
                  listner.onProgress(num, contentLength);
                }
              });
    } catch (Exception e) {

    }

    return "";
    //		return parseUpload(response);
  }
コード例 #4
0
  /**
   * 認証用トークン取得要求 Webでの認証後に呼び出される
   *
   * @throws IOException
   */
  public boolean getToken() throws IOException {
    // http://flickr.com/services/rest/?method=flickr.auth.getToken&api_key=987654321&frob=1a2b3c4d5e&api_sig=7f3870be274f6c49b3e31a0c6728957f.
    TreeMap<String, Object> map = new TreeMap<String, Object>();

    map.put(paramApiKey, apiKey);
    map.put(paramMethod, AUTH_GET_TOKEN);
    map.put(paramResponseFormat, jsonFormat);
    map.put(paramFlob, frob);
    map.put(paramApiSig, makeToken(map));

    RestRequestData request = new RestRequestData();
    request.setUrl(baseUrl);
    request.setPath(servicePath + "/" + restPath + "/");
    request.setQueryParam(map);

    URL url = RestfulLib.makeUrl(request);
    String response = RestfulLib.httpGetRequest(url.toString());

    return parseToken(response);
  }
コード例 #5
0
  /** redirect to flickr auth web pages. */
  public Uri redirectAuthPage() {
    // http://flickr.com/services/auth/?api_key=987654321&perms=write&frob=1a2b3c4d5e&api_sig=6f3870be274f6c49b3e31a0c6728957f
    TreeMap<String, Object> map = new TreeMap<String, Object>();

    map.put(paramApiKey, apiKey);
    map.put(paramPerm, "write");
    map.put(paramFlob, frob);
    map.put(paramApiSig, makeToken(map));

    RestRequestData request = new RestRequestData();
    request.setUrl(baseUrl);
    request.setPath(servicePath + "/" + authPath + "/");
    request.setQueryParam(map);

    URL url = RestfulLib.makeUrl(request);
    return Uri.parse(url.toString());
  }