Package com.google.appengine.api.urlfetch

Examples of com.google.appengine.api.urlfetch.HTTPResponse


      {
        Common.sendMessage(fromJID,"找不到该短ID对应的长ID,请重新输入或使用长ID");
        return;
      }
    }
    HTTPResponse response;
    response = api.statuses_destroy(fromJID, id);
    String strmessage;
    if(response.getResponseCode() == 200)
    {
      StatusJSON jsonstatus = new StatusJSON(new String(response.getContent()));
      strmessage = "成功删除消息: " + jsonstatus.getText();
    }
    else if(response.getResponseCode() == 404)
    {
      strmessage = "没有这条消息";
    }
    else if(response.getResponseCode() == 403)
    {
      strmessage = "这不是你的消息,不能删除";
    }
    else
    {
      strmessage = Common.getError(new String(response.getContent()));
      Common.log.info(Common.getStrJID(fromJID) + "del: " + new String(response.getContent()));
    }
    Common.sendMessage(fromJID,strmessage);
  }
View Full Code Here


    if(api == null)
    {
      Common.sendMessage(fromJID,"您尚未绑定账号,请使用-oauth命令绑定");
      return;
    }
    HTTPResponse response;
    if(msgarr.length == 1)
    {
      if(fav == true)                            //-fav
      {
        try {
View Full Code Here

    if(msgarr[1].isEmpty())
    {
      doHelp(fromJID,"fo");
      return;
    }
    HTTPResponse response;
    response = api.friendships_create_destroy(fromJID, msgarr[1],fo);
    String strmessage;
    if(response.getResponseCode() == 200)
    {
      if(fo)
      {
        strmessage = "成功关注 " + msgarr[1];
      }
      else
      {
        strmessage = "成功取消关注 " + msgarr[1];
      }
    }
    else if(response.getResponseCode() == 404)
    {
      strmessage = "找不到该用户";
    }
    else
    {
      strmessage = Common.getError(new String(response.getContent()));
    }
    Common.sendMessage(fromJID,strmessage);
  }
View Full Code Here

    if(api == null)
    {
      Common.sendMessage(fromJID,"您尚未绑定账号,请使用-oauth命令绑定");
      return;
    }
    HTTPResponse response;
    int msgarr_len = msgarr.length;
    if(msgarr_len == 1)
    {
      response = api.statuses_home_timeline(fromJID);
      Common.StatusShowResp(fromJID, response,1);
View Full Code Here

        {
          Common.sendMessage(fromJID,"找不到该短ID对应的长ID,请重新输入或使用长ID");
          return;
        }
      }
      HTTPResponse response;
      response = api.statuses_context_timeline(fromJID, id);
      if(response.getResponseCode() == 200)
      {
        Common.StatusShowResp(fromJID, response,4);
      }
      else if(response.getResponseCode() == 403)
      {
        Common.sendMessage(fromJID,"你没有通过这个用户的验证,无法查看TA的消息");
      }
      else if(response.getResponseCode() == 404)
      {
        Common.sendMessage(fromJID,"id所指定的消息不存在");
      }
      else
      {
        Common.sendMessage(fromJID,Common.getError(new String(response.getContent())));
        Common.log.info(Common.getStrJID(fromJID) + "-msg: " + new String(response.getContent()));
      }
    }
    else
    {
      doHelp(fromJID,"m");
View Full Code Here

      authorization = strBuf.toString();
     
      HTTPRequest request = new HTTPRequest(url,HTTPMethod.GET);
      request.addHeader(new HTTPHeader("Authorization",authorization));
      URLFetchService service = URLFetchServiceFactory.getURLFetchService();
      HTTPResponse response;
      try {
        response = service.fetch(request);
      } catch (SocketTimeoutException e) {
        Common.sendMessage(fromJID, "连接饭否超时,请重试");
        return;
      }
      if(response.getResponseCode() != 200)
      {
        String errMsg = "出现错误,请重试";
        Common.sendMessage(fromJID,errMsg);
        Common.log.warning(strJID + " :" + String.valueOf(response.getResponseCode()) + ": " + new String(response.getContent()));
        return;
      }
     
      /* 提取接收到的未经授权的Request Token */
      String tokenstring = new String(response.getContent());
      String[] tokenarr = tokenstring.split("&");
      String[] tokenarr2 = tokenarr[0].split("=");
      String oauth_token = tokenarr2[1];
      Common.setData(fromJID,"Account","request_token",oauth_token);
     
      /* 请求用户授权Request Token */
      String strMessage = "请访问以下网址获取PIN码: \n http://fanfou.com/oauth/authorize?oauth_token="
            + oauth_token + "&oauth_callback=oob"
            + " \n 手机用户请访问: \n http://m.fanfou.com/oauth/authorize?oauth_token="
            + oauth_token + "&oauth_callback=oob"
            + " \n 然后使用\"-bind PIN码\"命令绑定账号。";
      Common.sendMessage(fromJID,strMessage);
    }
    else if(msgarr.length == 3)                        //XAuth
    {
      URL url = new URL("http://fanfou.com/oauth/access_token");
      String username = msgarr[1];
      String password = msgarr[2];
      params = "oauth_consumer_key=" + API.consumer_key
          + "&oauth_nonce=" + String.valueOf(nonce)
          + "&oauth_signature_method=HMAC-SHA1"
          + "&oauth_timestamp=" + String.valueOf(timestamp)
          + "&x_auth_username=" + username
          + "&x_auth_password=" + password
          + "&x_auth_mode=client_auth";
   
      params = "GET&" + URLEncoder.encode(url.toString(),"UTF-8")
            + "&" + URLEncoder.encode(params,"UTF-8");
      String sig = API.generateSignature(params);
     
      authorization = "OAuth realm=\"Fantalker\",oauth_consumer_key=\"" + API.consumer_key
            + "\",oauth_signature_method=\"HMAC-SHA1\""
            + ",oauth_timestamp=\"" + String.valueOf(timestamp) + "\""
            + ",oauth_nonce=\"" + String.valueOf(nonce) + "\""
            + ",oauth_signature=\"" + sig + "\""
            + ",x_auth_username=\"" + username + "\""
            + ",x_auth_password=\"" + password + "\""
            + ",x_auth_mode=\"client_auth\"";
     
     
      HTTPRequest request = new HTTPRequest(url,HTTPMethod.GET);
      request.addHeader(new HTTPHeader("Authorization",authorization));
      URLFetchService service = URLFetchServiceFactory.getURLFetchService();
      HTTPResponse response;
      try {
        response = service.fetch(request);
      } catch (SocketTimeoutException e) {
        Common.sendMessage(fromJID, "连接饭否超时,请重试");
        return;
      }
     
      if(response.getResponseCode() == 200)
      {
        //继续执行
      }
      else if(response.getResponseCode() == 401)
      {
        Common.sendMessage(fromJID, "用户名或密码错误,请重试");
        return;
      }
      else
      {
        Common.sendMessage(fromJID,"未知错误,请重试");
        Common.log.info(Common.getStrJID(fromJID) + " xauth:" + new String(response.getContent()));
        return;
      }
      try {
        /* 提取接收到的未经授权的Request Token */
        String tokenstring = new String(response.getContent());
        String[] tokenarr = tokenstring.split("&");
        String[] tokenarr2 = tokenarr[0].split("=");
        String oauth_token = tokenarr2[1];
        tokenarr2 = tokenarr[1].split("=");
        String oauth_token_secret = tokenarr2[1];
View Full Code Here

    if(api == null)
    {
      Common.sendMessage(fromJID,"您尚未绑定账号,请使用-oauth命令绑定");
      return;
    }
    HTTPResponse response;
    response = api.statuses_public_timeline(fromJID);
    Common.StatusShowResp(fromJID, response,5);
  }
View Full Code Here

    if(api == null)
    {
      Common.sendMessage(fromJID,"您尚未绑定账号,请使用-oauth命令绑定");
      return;
    }
    HTTPResponse response;
    int msgarr_len = msgarr.length;
    if(msgarr_len == 1)
    {
      response = api.statuses_mentions(fromJID);
      Common.StatusShowResp(fromJID, response,2);
    }
    else if(msgarr_len == 2)                        //-@ p2
    {
      char ch;
      ch = msgarr[1].charAt(0);
      if(ch != 'p' && ch != 'P')
      {
        Common.sendMessage(fromJID,"无效命令");
        return;
      }
      msgarr[1] = msgarr[1].substring(1);
      if(!Common.isNumeric(msgarr[1]))
      {
        Common.sendMessage(fromJID,"无效命令");
        return;
      }
      response = api.statuses_mentions(fromJID, msgarr[1]);
      Common.StatusShowResp(fromJID, response,2,msgarr[1]);
    }
    else                                  //-@ -WNEO5ZQt28 test t
    {
      int intIndex = strMessage.lastIndexOf(msgarr[1]) + msgarr[1].length() + 1;
      String replyMsg = strMessage.substring(intIndex);
      String id = msgarr[1];
      if(id.length()<=2)
      {
        id = Common.shortID2ID(fromJID, id);
        if(id == null)
        {
          Common.sendMessage(fromJID,"找不到该短ID对应的长ID,请重新输入或使用长ID");
          return;
        }
      }
      response = api.statuses_reply(fromJID, replyMsg, id);
      if(response == null)
      {
        return;
      }
      if(response.getResponseCode() == 200)
      {
        StatusJSON jsonStatus = new StatusJSON(new String(response.getContent()));
        Common.sendMessage(fromJID,"成功回复\n  " + jsonStatus.getText());
      }
      else if(response.getResponseCode() == 400)
      {
        try {
          JSONObject json = new JSONObject(new String(response.getContent()));
          String error = json.getString("error");
          Common.sendMessage(fromJID,error);
         
        } catch (JSONException e) {
          //e.printStackTrace();
          Common.log.warning(Common.getStrJID(fromJID) + " @:" + new String(response.getContent()));
          Common.sendMessage(fromJID,"未知错误");
        }
      }
      else
      {
        Common.sendMessage(fromJID,"未知错误");
        Common.log.info(Common.getStrJID(fromJID) + " rt:" + new String(response.getContent()));
      }

    }
  }
View Full Code Here

    if(api == null)
    {
      Common.sendMessage(fromJID,"您尚未绑定账号,请使用-oauth命令绑定");
      return;
    }
    HTTPResponse response;
    int msgarr_len = msgarr.length;
    if(msgarr_len == 1)
    {
      doHelp(fromJID,"rt");
    }
    else                                  //-rt -WNEO5ZQt28 test t
    {
      int intIndex;
      String replyMsg;
      try{
        intIndex = strMessage.lastIndexOf(msgarr[1]) + msgarr[1].length() + 1;
        replyMsg = strMessage.substring(intIndex);
      } catch (StringIndexOutOfBoundsException e) {
        replyMsg = "";
      }
 
      String id = msgarr[1];
      if(id.length()<=2)
      {
        id = Common.shortID2ID(fromJID, id);
        if(id == null)
        {
          Common.sendMessage(fromJID,"找不到该短ID对应的长ID,请重新输入或使用长ID");
          return;
        }
      }
      response = api.statuses_repost(fromJID, replyMsg, id);
      if(response.getResponseCode() == 200)
      {
        StatusJSON jsonStatus = new StatusJSON(new String(response.getContent()));
        Common.sendMessage(fromJID,"成功转发\n  " + jsonStatus.getText());
      }
      else
      {
        Common.sendMessage(fromJID,Common.getError(new String(response.getContent())));
        Common.log.info(Common.getStrJID(fromJID) + " rt:" + new String(response.getContent()));
      }
    }
  }
View Full Code Here

    if(api == null)
    {
      Common.sendMessage(fromJID,"您尚未绑定账号,请使用-oauth命令绑定");
      return;
    }
    HTTPResponse response;
    response = api.statuses_send(fromJID,message);
    if(response.getResponseCode() == 200)
    {
      Common.sendMessage(fromJID,"成功发布状态");
    }
    else
    {
      Common.sendMessage(fromJID,Common.getError(new String(response.getContent())));
      Common.log.info(Common.getStrJID(fromJID) + "status.send: " + new String(response.getContent()));
    }
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.urlfetch.HTTPResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.