本文介绍了使用VB.NET http请求阅读推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话给makeRequest时没有收到推文()

我得到以下结果



I am not getting tweets when I call makeRequest()
I am getting following result

[{"created_at":"Mon Mar 21 18:05:13 +0000 2016","id":711976973719867393,"id_str":"711976973719867393","text":"My twitter test2","entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[]},"truncated":false,"source":"\u003ca href=\"https:\/\/twitter.com\/sgramesh75\" rel=\"nofollow\"\u003eshjtweet2\u003c\/a\u003e","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":1070473861,"id_str":"1070473861","name":"ramesh sunderasan","screen_name":"sgramesh75","location":"Sharjah, United Arab Emirates","description":"","url":"https:\/\/t.co\/OSutcvafot","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/OSutcvafot","expanded_url":"https:\/\/twitter.com\/sharjahtv","display_url":"twitter.com\/sgramesh75","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":5,"friends_count":2,"listed_count":0,"created_at":"Tue Jan 08 09:43:26 +0000 2013","favourites_count":0,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":3,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_2_normal.png","profile_image_url_https":"https:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_2_normal.png","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":true,"default_profile":true,"default_profile_image":true,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"favorited":false,"retweeted":false,"lang":"en"},{"created_at":"Mon Mar 21 18:01:01 +0000 2016","id":711975919431200768,"id_str":"711975919431200768","text":"My twitter test","entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[]},"truncated":false,"source":"\u003ca href=\"https:\/\/twitter.com\/sharjahnews\" rel=\"nofollow\"\u003eshjtweet2\u003c\/a\u003e","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":1070473861,"id_str":"1070473861","name":"ramesh sunderasan","screen_name":"sgramesh75","location":"Sharjah, United Arab Emirates","description":"","url":"https:\/\/t.co\/OSutcvafot","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/OSutcvafot","expanded_url":"https:\/\/twitter.com\/sharjahtv","display_url":"twitter.com\/sharjahtv","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":5,"friends_count":2,"listed_count":0,"created_at":"Tue Jan 08 09:43:26 +0000 2013","favourites_count":0,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":3,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_2_normal.png","profile_image_url_https":"https:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_2_normal.png","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":true,"default_profile":true,"default_profile_image":true,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"favorited":false,"retweeted":false,"lang":"en"},{"created_at":"Fri Jul 12 14:05:30 +0000 2013","id":355689377319485442,"id_str":"355689377319485442","text":"ARE YOU READY to hear about the newest trick in shredding so much extra off... ASAP? http:\/\/t.co\/jxINV2tAH6","entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[{"url":"http:\/\/t.co\/jxINV2tAH6","expanded_url":"http:\/\/WOMENHEALTHBLOG.COM-new.net\/july?narshkcjpy","display_url":"WOMENHEALTHBLOG.COM-new.net\/july?narshkcjpy","indices":[85,107]}]},"truncated":false,"source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":1070473861,"id_str":"1070473861","name":"ramesh sunderasan","screen_name":"sgramesh75","location":"Sharjah, United Arab Emirates","description":"","url":"https:\/\/t.co\/OSutcvafot","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/OSutcvafot","expanded_url":"https:\/\/twitter.com\/sharjahtv","display_url":"twitter.com\/sharjahtv","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":5,"friends_count":2,"listed_count":0,"created_at":"Tue Jan 08 09:43:26 +0000 2013","favourites_count":0,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":3,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_2_normal.png","profile_image_url_https":"https:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_2_normal.png","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":true,"default_profile":true,"default_profile_image":true,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"}]





我尝试过:





What I have tried:

Public Function makeRequest(ByVal query As String)
        Dim requestResult As String = ""
        oauth_nonce = setNounce()
        oauth_timestamp = setTimeStamp()
        Dim oauth_signature As String = getSignature(oauth_consumer_key, oauth_nonce, oauth_timestamp, oauth_token, consumer_secret, oauth_token_secret, query)


        'Set the authorization header
        Dim headerFormat As String = "OAuth oauth_nonce=""{0}"", oauth_signature_method=""{1}"", oauth_timestamp=""{2}"", oauth_consumer_key=""{3}"", oauth_token=""{4}"", oauth_signature=""{5}"", oauth_version=""{6}"""
        Dim authHeader As String = String.Format(headerFormat, Uri.EscapeDataString(oauth_nonce), Uri.EscapeDataString(oauth_signature_method), Uri.EscapeDataString(oauth_timestamp), Uri.EscapeDataString(oauth_consumer_key), Uri.EscapeDataString(oauth_token), Uri.EscapeDataString(oauth_signature), Uri.EscapeDataString(oauth_version))


        'set the request
        ServicePointManager.Expect100Continue = False
        Dim request As WebRequest
        Dim response As HttpWebResponse
        Dim streamReader As System.IO.StreamReader
        Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
        request = WebRequest.Create(requestUrl & "?" & reqParam(query))
        request.Timeout = -1
        request .Headers.Add("Authorization", authHeader)

        Try
            response = DirectCast(request.GetResponse(), HttpWebResponse)
            streamReader = New System.IO.StreamReader(response.GetResponseStream(), True)
            requestResult = streamReader.ReadLine()
            request.Abort()
            streamReader.Close()
            streamReader = Nothing
            response.Close()
            response = Nothing
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try

        Return requestResult
    End Function

推荐答案

[
  {
    "created_at": "Mon Mar 21 18:05:13 +0000 2016",
    "id": 711976973719867400,
    "id_str": "711976973719867393",
    "text": "My twitter test2",
    "entities": {
      "hashtags": [],
      "symbols": [],
      "user_mentions": [],
      "urls": []
    },
    "truncated": false,
    "source": "<a href=\"https://twitter.com/sgramesh75\" rel=\"nofollow\">shjtweet2</a>",
    "in_reply_to_status_id": null,
    "in_reply_to_status_id_str": null,
    "in_reply_to_user_id": null,
    "in_reply_to_user_id_str": null,
    "in_reply_to_screen_name": null,
    "user": {
      "id": 1070473861,
      "id_str": "1070473861",
      "name": "ramesh sunderasan",
      "screen_name": "sgramesh75",
      "location": "Sharjah, United Arab Emirates",
      "description": "",
      "url": "https://t.co/OSutcvafot",
      "entities": {
        "url": {
          "urls": [
            {
              "url": "https://t.co/OSutcvafot",
              "expanded_url": "https://twitter.com/sharjahtv",
              "display_url": "twitter.com/sgramesh75",
              "indices": [
                0,
                23
              ]
            }
          ]
        },
        "description": {
          "urls": []
        }
      },
      "protected": false,
      "followers_count": 5,
      "friends_count": 2,
      "listed_count": 0,
      "created_at": "Tue Jan 08 09:43:26 +0000 2013",
      "favourites_count": 0,
      "utc_offset": null,
      "time_zone": null,
      "geo_enabled": false,
      "verified": false,
      "statuses_count": 3,
      "lang": "en",
      "contributors_enabled": false,
      "is_translator": false,
      "is_translation_enabled": false,
      "profile_background_color": "C0DEED",
      "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
      "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
      "profile_background_tile": false,
      "profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
      "profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
      "profile_link_color": "0084B4",
      "profile_sidebar_border_color": "C0DEED",
      "profile_sidebar_fill_color": "DDEEF6",
      "profile_text_color": "333333",
      "profile_use_background_image": true,
      "has_extended_profile": true,
      "default_profile": true,
      "default_profile_image": true,
      "following": false,
      "follow_request_sent": false,
      "notifications": false
    },
    "geo": null,
    "coordinates": null,
    "place": null,
    "contributors": null,
    "is_quote_status": false,
    "retweet_count": 0,
    "favorite_count": 0,
    "favorited": false,
    "retweeted": false,
    "lang": "en"
  },
  {
    "created_at": "Mon Mar 21 18:01:01 +0000 2016",
    "id": 711975919431200800,
    "id_str": "711975919431200768",
    "text": "My twitter test",
    "entities": {
      "hashtags": [],
      "symbols": [],
      "user_mentions": [],
      "urls": []
    },
    "truncated": false,
    "source": "<a href=\"https://twitter.com/sharjahnews\" rel=\"nofollow\">shjtweet2</a>",
    "in_reply_to_status_id": null,
    "in_reply_to_status_id_str": null,
    "in_reply_to_user_id": null,
    "in_reply_to_user_id_str": null,
    "in_reply_to_screen_name": null,
    "user": {
      "id": 1070473861,
      "id_str": "1070473861",
      "name": "ramesh sunderasan",
      "screen_name": "sgramesh75",
      "location": "Sharjah, United Arab Emirates",
      "description": "",
      "url": "https://t.co/OSutcvafot",
      "entities": {
        "url": {
          "urls": [
            {
              "url": "https://t.co/OSutcvafot",
              "expanded_url": "https://twitter.com/sharjahtv",
              "display_url": "twitter.com/sharjahtv",
              "indices": [
                0,
                23
              ]
            }
          ]
        },
        "description": {
          "urls": []
        }
      },
      "protected": false,
      "followers_count": 5,
      "friends_count": 2,
      "listed_count": 0,
      "created_at": "Tue Jan 08 09:43:26 +0000 2013",
      "favourites_count": 0,
      "utc_offset": null,
      "time_zone": null,
      "geo_enabled": false,
      "verified": false,
      "statuses_count": 3,
      "lang": "en",
      "contributors_enabled": false,
      "is_translator": false,
      "is_translation_enabled": false,
      "profile_background_color": "C0DEED",
      "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
      "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
      "profile_background_tile": false,
      "profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
      "profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
      "profile_link_color": "0084B4",
      "profile_sidebar_border_color": "C0DEED",
      "profile_sidebar_fill_color": "DDEEF6",
      "profile_text_color": "333333",
      "profile_use_background_image": true,
      "has_extended_profile": true,
      "default_profile": true,
      "default_profile_image": true,
      "following": false,
      "follow_request_sent": false,
      "notifications": false
    },
    "geo": null,
    "coordinates": null,
    "place": null,
    "contributors": null,
    "is_quote_status": false,
    "retweet_count": 0,
    "favorite_count": 0,
    "favorited": false,
    "retweeted": false,
    "lang": "en"
  },
  {
    "created_at": "Fri Jul 12 14:05:30 +0000 2013",
    "id": 355689377319485440,
    "id_str": "355689377319485442",
    "text": "ARE YOU READY to hear about the newest trick in shredding so much extra off... ASAP? http://t.co/jxINV2tAH6",
    "entities": {
      "hashtags": [],
      "symbols": [],
      "user_mentions": [],
      "urls": [
        {
          "url": "http://t.co/jxINV2tAH6",
          "expanded_url": "http://WOMENHEALTHBLOG.COM-new.net/july?narshkcjpy",
          "display_url": "WOMENHEALTHBLOG.COM-new.net/july?narshkcjpy",
          "indices": [
            85,
            107
          ]
        }
      ]
    },
    "truncated": false,
    "source": "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>",
    "in_reply_to_status_id": null,
    "in_reply_to_status_id_str": null,
    "in_reply_to_user_id": null,
    "in_reply_to_user_id_str": null,
    "in_reply_to_screen_name": null,
    "user": {
      "id": 1070473861,
      "id_str": "1070473861",
      "name": "ramesh sunderasan",
      "screen_name": "sgramesh75",
      "location": "Sharjah, United Arab Emirates",
      "description": "",
      "url": "https://t.co/OSutcvafot",
      "entities": {
        "url": {
          "urls": [
            {
              "url": "https://t.co/OSutcvafot",
              "expanded_url": "https://twitter.com/sharjahtv",
              "display_url": "twitter.com/sharjahtv",
              "indices": [
                0,
                23
              ]
            }
          ]
        },
        "description": {
          "urls": []
        }
      },
      "protected": false,
      "followers_count": 5,
      "friends_count": 2,
      "listed_count": 0,
      "created_at": "Tue Jan 08 09:43:26 +0000 2013",
      "favourites_count": 0,
      "utc_offset": null,
      "time_zone": null,
      "geo_enabled": false,
      "verified": false,
      "statuses_count": 3,
      "lang": "en",
      "contributors_enabled": false,
      "is_translator": false,
      "is_translation_enabled": false,
      "profile_background_color": "C0DEED",
      "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
      "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
      "profile_background_tile": false,
      "profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
      "profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
      "profile_link_color": "0084B4",
      "profile_sidebar_border_color": "C0DEED",
      "profile_sidebar_fill_color": "DDEEF6",
      "profile_text_color": "333333",
      "profile_use_background_image": true,
      "has_extended_profile": true,
      "default_profile": true,
      "default_profile_image": true,
      "following": false,
      "follow_request_sent": false,
      "notifications": false
    },
    "geo": null,
    "coordinates": null,
    "place": null,
    "contributors": null,
    "is_quote_status": false,
    "retweet_count": 0,
    "favorite_count": 0,
    "favorited": false,
    "retweeted": false,
    "possibly_sensitive": false,
    "lang": "en"
  }
]



It is actually an array of 3 tweets...To learn about the inner structure of each tweet, you should go to the documentation: []


这篇关于使用VB.NET http请求阅读推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 17:05