I'm writing a .NET 4.0 app and I need to dynamically create shortened bitly links. I created a bitly OAuth Application and I have my access token.
When I enter something like this in a browser I get the bitly link back as expected:
https://api-ssl.bitly.com/v3/shorten?access_token=< my access token here >&format=txt&longUrl=http%3A%2F%2Fgoogle.com%2F
(of course, I replace "< my access token here >" with my actual access token)
In my .NET app I pass the exact same URL to some code (see below) to get the response to the HTTP Request. This is vanilla code I've used before in many different situations. Now I'm getting a "MISSING_ARG_ACCESS_TOKEN" error back from bitly in the response, even though I'm clearly passing the access token in the URL.
Any ideas why I'm getting this error? I'd greatly appreciate any help. The only thing I can think of is that when it works in the browser, the browser is doing something else behind the scenes when making the request that my code is not doing.
Dim uri As New Uri(URL)
If (uri.Scheme = uri.UriSchemeHttp) Or (uri.Scheme = uri.UriSchemeHttps) Then
Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
request.Method =
WebRequestMethods.Http.Post Dim response As HttpWebResponse = request.GetResponse()
Dim reader As New IO.StreamReader(response.GetResponseStream())
Dim tmp As String = reader.ReadToEnd()
response.Close()
Return tmp
End If