• 怎么使用获得的OAuth2.0 Access Token调用API


     

    String url=" url?access_token="+access_token;

    HttpGet request=new HttpGet(url);

    System.out.println("保存的access_token="+access_token);
    HttpClient client=new GetDefaultClient().getNewHttpClient();

    try
    {

    HttpResponse response=client.execute(request);

    int code=response.getStatusLine().getStatusCode();
    if (code == 200)
    {

    InputStream is = response.getEntity().getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
    StringBuilder buffer = new StringBuilder();
    try
    {
    String line;
    while ((line=reader.readLine())!=null)
    {
    buffer.append(line);
    }
    } finally
    {
    reader.close();
    }
    String string = buffer.toString();
    System.out.println(string);

    //return Integer.parseInt(string);

    }
    } catch (UnsupportedEncodingException e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (ClientProtocolException e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
  • 相关阅读:
    白话机器学习
    Intersecting Lines POJ
    Segments POJ
    Toy Storage POJ
    TOYS POJ
    2019CCPC秦皇岛赛区1004 Decimal
    Django 基本使用
    HTML页面布局
    微擎上传视频,音频,图片提示格式不支持
    微擎应用名称图标的修改
  • 原文地址:https://www.cnblogs.com/tonny-li/p/5629584.html
Copyright © 2020-2023  润新知