zoukankan      html  css  js  c++  java
  • 获取人人网上的新鲜事

    第一步:在你的人人网页面上添加 “开发者”  我在人人网上找了半天 没找到。只好输入 http://dev.renren.com.

    按照上面的提示 一步一步完成,系统生成如下参数:

    APP ID149931

    API Key 9226a67eb392494bb251e4a1fc5943bc

    Secret 35325078d5b6454c91529cbf63378b8a

    这两个参数  相当重要  。

    在 文档标签页下面 有个:SDK ,点击打开 ,选择:Java SDK (内含测试代码) ,下载到一个本地文件夹中。

     

    第二步:

     

    第三步,在GOOGLE里搜 如下 三个包。

    commons-codec-1.4.jar

    commons-httpclient-3.1 (1).jar

    commons-logging-1.1.1.jar

    放到第二步的文件夹中,先不管干什麽用的。

     

    第三步,

    https://graph.renren.com/oauth/authorize?client_id=9226a67eb392494bb251e4a1fc5943bc&response_type=token&redirect_uri=http://graph.renren.com/oauth/login_success.html&scope=read_user_feed

    将红色的替换为 你刚才申请的API KEY。在浏览器中打开。会出现新的链接

    http://graph.renren.com/oauth/login_success.html#access_token=149931%7C6.c884a9a8cf8e6400c69f0aa34d9e8582.2592000.1313211600-231348691&expires_in=2594055&scope=read_user_feed  

    将红色的复制出来。替换下面红色的,并在浏览器中打开。

    http://graph.renren.com/renren_api/session_key?oauth_token=149931%7C6.6df79f050714764b34e9da2b4deedae7.2592000.1313208000-388064919

    浏览器中汇出现一段JSON 的语句 如下:

    {"renren_token":{"session_secret":"4d286b539fca8705f9c4d8014ebe994b","expires_in":2593879,"session_key":"6.c884a9a8cf8e6400c69f0aa34d9e8582.2592000.1313211600-231348691"},"oauth_token":"149931|6.c884a9a8cf8e6400c69f0aa34d9e8582.2592000.1313211600-231348691","user":{"id":231348691}} 把红色的拷贝出来。 第三步: 打开eclipse,新建JAVA工程。导入库文件,库文件在第一步和第二部下载的。jre文件。 新建一个类: 添加如下: public static void main(String[] args) { 
    // TODO Auto-generated method stub 
    // System.out.println("hello world!"); 
    // int i=0; 
    // RenrenApiConfig mRenrenApiConfig=new RenrenApiConfig(); 
    // mRenrenApiConfig.renrenApiKey="237f3c9af4f44ade935f2854b95749aa";
    // mRenrenApiConfig.renrenApiSecret="31aa13eff295447f8ef347a806c18e99"; 
    // String token="123564|7C6.55691196c67ee2d58fde40078b68ae2e.2592000.1313136000-231348691"; 
    // String session="6.55691196c67ee2d58fde40078b68ae2e.2592000.1313136000-231348691"; 
    // boolean isAccessToken=true; 
    // RenrenApiClient mRenrenApiClient=new RenrenApiClient(session); 
    // FriendsService mFriendsService=mRenrenApiClient.getFriendsService();
    // List<Integer> mFriendId=mFriendsService.getFriendIds(0, 1); 
    // for(i=0;i<mFriendId.size();i++) 
    // System.out.println(Integer.toString(mFriendId.get(i))); 

    long time = System.currentTimeMillis(); 
    String strTime = URLEncoder.encode(String.valueOf(time)); //系统的当前时间,作为call_id的值 
    String secret = "35325078d5b6454c91529cbf63378b8a"; //应用的Secret Key 
    String apiKey = "9226a67eb392494bb251e4a1fc5943bc"; //应用的API Key
    String requestMethod = "feed.get"; //接口名称 
    String v = "1.0"; //API的版本号,请设置成1.0 
    String sessionKey = "6.6df79f050714764b34e9da2b4deedae7.2592000.1313208000-388064919"; //通过上述验证授权过程得到的Session Key,注意需要URL编码 
    String type = "10,40"; //请求接口所要求的参数,因接口不同而不同,下面接口列表中点击接口名进入的页面会详细介绍 
    String url = "http://api.renren.com/restserver.do"; //请求人人网开放平台API服务器的地址 //上述的签名 

    PostMethod method = new PostMethod(url); 
    List<String> paramlist=new ArrayList<String>(); 
    paramlist.add("api_key="+apiKey); 
    paramlist.add("call_id="+strTime); 
    paramlist.add("format=JSON"); 
    paramlist.add("method="+requestMethod); 
    paramlist.add("type="+type); 
    paramlist.add("v="+v); 
    paramlist.add("session_key="+sessionKey); 

    String secretkey=secret; 
    String signature=getSignature(paramlist,secretkey); 

    //将以上准备好的参数添加到method对象中 
    method.addParameter("api_key", apiKey); 
    method.addParameter("method", requestMethod); 
    method.addParameter("call_id", strTime); 
    method.addParameter("sig", signature); 
    method.addParameter("v", v); 
    method.addParameter("session_key", sessionKey); 
    method.addParameter("type", type); 
    method.addParameter("format", "JSON"); //返回结果的形式,支持XML或者JSON两种形式,默认为XML 

    HttpClient client = new HttpClient(); 
    String in=""; 
    int maxlen=10000000; 
    try{ 
    client.executeMethod(method); 
    } 
    catch(Exception e) 
    { 

    } 
    try 
    { 
    in=method.getResponseBodyAsString(maxlen); //返回请求的结果 
    } 
    catch(Exception e) 
    { 

    } 
    System.out.println(in); 

    } 
    public static String getSignature(List<String> paramList,String secret){ 

    Collections.sort(paramList); 
    StringBuffer buffer = new StringBuffer(); 
    for (String param : paramList) { 
    buffer.append(param); //将参数键值对,以字典序升序排列后,拼接在一起 
    } 
    buffer.append(secret); //符串末尾追加上应用的Secret Key 
    try { //下面是将拼好的字符串转成MD5值,然后返回 
    java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); 
    StringBuffer result = new StringBuffer(); 
    try { 
    for (byte b : md.digest(buffer.toString().getBytes("UTF-8"))) { 
    result.append(Integer.toHexString((b & 0xf0) >>> 4)); 
    result.append(Integer.toHexString(b & 0x0f)); 
    } 
    } catch (UnsupportedEncodingException e) { 
    for (byte b : md.digest(buffer.toString().getBytes())) { 
    result.append(Integer.toHexString((b & 0xf0) >>> 4)); 
    result.append(Integer.toHexString(b & 0x0f)); 
    } 
    } 
    return result.toString(); 
    } catch (java.security.NoSuchAlgorithmException ex) { 
    //Log.e("ERROR "," has happen"); 
    } 
    return null; 
    } 

    }

    用第三步拷贝的红色字符 替换红色的字符,在爸API KEY  和secret 按照建立应用 的时候的参数 修改。

    注释那些程序是基本的SDK 里面,如获取好友头像。信息/照片/博文等。可以打开用的。

    运行 结果如下:

     [{"message":"严重鄙视那些靠着父母和亲戚关系进入政府部门的人,然后在校内上发些恶心的状态,今天开会,明天唱红歌。你们他妈的拿脸皮厚当资本来炫耀了,如果凭本事吃饭,哪有你们的份?","actor_id":231348691,"update_time":"2011-06-30 13:40:35","source_id":2156786595,"actor_type":"user","likes":{"friend_count":0,"user_like":0,"total_count":0},"name":"郭瑞(gorv)","feed_type":10,"post_id":10559232264,"headurl":"http://hdn.xnimg.cn/photos/hdn521/20100526/2040/tiny_aij1_103957j019116.jpg","comments":{"count":13,"comment":[{"uid":221376882,"comment_id":7298940616,"time":"2011-06-30 14:20","text":"\"哥,过于激动了,淡定!\"","name":"杨集友","headurl":"http://hdn.xnimg.cn/photos/hdn521/20110616/1600/tiny_r3fZ_247549p019118.jpg"},{"uid":241446200,"comment_id":7395421204,"time":"2011-07-06 19:44","text":"\"淡定,进政府能混开也是本事\"","name":"朱胜佳","headurl":"http://hdn.xnimg.cn/photos/hdn421/20110514/2320/tiny_xnMR_11532d019118.jpg"}]}}]

    我这是个测试账户 ,所以只有我一位好友:

     

      说一点 :人人这个开发文档 太烂了。所有的东西都找不带 。真的差经,人人换不支持用英文名注册

  • 相关阅读:
    每行显示多少个
    CentOS挂载NTFS格式硬盘
    BAT教程 :第一节(批处理基础)
    BAT教程 第三节(FOR命令中的变量)
    BAT教程 :第二节(for命令详解 )
    USB设备读取的相关问题
    BAT教程 :第四节(批处理中的变量)
    内核级HOOK的几种实现与应用
    书籍链接
    BAT教程 :第五节(set命令详解)
  • 原文地址:https://www.cnblogs.com/changefuture/p/2300970.html
Copyright © 2011-2022 走看看