Every time I run the following code I get an exception:
Code
Dim url As String = "https://graph.facebook.com/search?q=" & System.Web.HttpUtility.UrlEncode(_sourceData.Rows(i).Item(0).ToString) & "&type=event&limit=5000"
Dim getFullURL As String = (url & Convert.ToString("&access_token=")) + _appToken
Dim stream As New StreamReader(HttpWebRequest.Create(getFullURL).GetResponse().GetResponseStream())
Dim output As String = stream.ReadToEnd()
stream.Close()
Exception:
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (400) Bad Request.
My first thought was that it could be an execution limit Facebook has in place over each of their API access tokens; however, if I copy the contents of the 'getFullURL' string variable during runtime and paste it directly into my internet browser, it works fine. Given that it works to copy-paste into web browser, I'm very stuck on how to continue troubleshooting!
Any advice would be most appreciated.
This was related to me hitting the maximum API calls (200/hr). I had an erroneous loop that kept repeating the API call during my testing that made me hit this limit.
Related
I am trying a "GET" method to request a count of activities from the Accelo API here:
https://api.accelo.com/docs/?http#count-activities
And although i've used a very similar POST method to successfully get the access token using an authentication method, I cannot for the life of me figure out how to get the count of activities. The API says to use "GET" and past the access token as "bearer..." and I've also tried doing a post and getting the stream first, tried sending in some data and accessing the "list activities" endpoint instead...nothing is working. everything I do returns the error "400. Bad Request."
I've tried passing data in a query string format directly in the URI, and tried passing no data since its a GET function. It looks to me like I'm following the API exactly.
Dim data2 = Nothing ' Encoding.UTF8.GetBytes(jsonstring)
Dim _list = GetListOfActivities(New Uri("https://example.api.accelo.com/api/v0/activities/count.xml"), data2, _AccessToken)
Dim reqa As WebRequest = WebRequest.Create(uri)
' reqa.Method = "GET"
reqa.Headers.Add("GET", "/api/v0/activities/count.xml HTTP/1.1")
reqa.Headers.Add("Authorization", "Bearer " & _AccessToken)
reqa.ContentType = "application/x-www-form-urlencoded"
'reqa.ContentLength = jsonDataBytes.Length
' Dim streama = reqa.GetRequestStream()
' streama.Write(jsonDataBytes, 0, jsonDataBytes.Length)
'streama.Close()
Dim responsea As WebResponse = reqa.GetResponse()
Console.WriteLine((CType(responsea, HttpWebResponse)).StatusDescription)
I must be formatting the request wrong - please help?
My problem turned out to be something stupid, and literally beyond the scope of what I posted here. I had specified a "scope" in my initial request to get the access token that was set to read-only "staff" data (I had copied-and-pasted their example online into my code, for other parameters like grant type, and I brought the scope along with it), and in this scenario here I was trying to access "activities" data and not "staff" data. I would have thought I'd get a permissions-related error, instead of "bad request" which confused me, but anyway it works now.
The above code - actually with this line:
reqa.Method = "GET"
instead of this line:
reqa.Headers.Add("GET", "/api/v0/activities/count.xml HTTP/1.1")
Works just fine since I changed my scope to read(all) in my initial web method getting the access token.
I am getting an error while creating Envelope using following code. But authentication is successful and I am able to retrieve Account Id.
Authentication code:
string authHeader = "{\"Username\":\"" + Username + "\", \"Password\":\"" + Password + "\", \"IntegratorKey\":\"" + IntegratorKey + "\"}";
cfg.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
AuthenticationApi authApi = new AuthenticationApi(cfg);
Envelope Creation code Code:
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(AccountId, envDef);
Error details:
A first chance exception of type 'DocuSign.eSign.Client.ApiException' occurred in DocuSign.eSign.dll
Error: Error calling CreateEnvelope: {
"errorCode": "PARTNER_AUTHENTICATION_FAILED",
"message": "The specified Integrator Key was not found or is disabled. An Integrator key was not specified."
}
Any help will be appreciated.
The error "PARTNER_AUTHENTICATION_FAILED" is the first failure before even the body is read, it means the Integrator Key is NOT valid for the environment, method call "Reserved" or Missing as the "message" states.
Most of the time this happens in a functioning system with the Integrator Key is "Turned off" if the system is doing something not allowed aka stuck in a loop of making a "reserved" call. If you have been testing and now went live in prod, it means your Integrator Key is NOT allowed in Production.
To help you the best way is to capture exact JSON/SOAP request posted by your API calls via Java to DocuSign by following steps explained at this DocuSign support article https://support.docusign.com/guides/ndse-user-guide-api-request-logging
Please post these and what actual DocuSign API call you are trying to make and I am sure it will be we will be able to deduce the issue.
I'm making a call to the SalesForce REST Api.
However, I have a very weird error. Initially I wrote this in a VB.NET Module file. Everything was working correctly, as soon as I put the method in a class I keep getting the darn Invalid Session ID error. The error doesn't seem to suggest which part of the code is failing.
I am using RestSharp to facilitate the call to the SalesForce API, and I know for a fact it works because in the Module file I am able to fetch the data that I need.
I do not understand the rationale about why it works in the Module file but not in a class file.
Anyways, here is the code that I've placed in both the class file and the Module file to facilitate the call:
client = New RestClient(_strURI)
request = New RestRequest(Method.POST)
request.AddParameter("grant_type", "password")
request.AddParameter("client_id", _strClientID)
request.AddParameter("client_secret", _strClientSecret)
request.AddParameter("redirect_uri", _strRedirectUrl)
request.AddParameter("username", _strUserName)
request.AddParameter("password", _strPassword & _strSecurityToken)
'Dim response As IRestResponse
Dim response As IRestResponse = Nothing
response = client.Execute(request)
'This is the offending line in the class file..it returns back a HTTP 200 yet gives me that Session Invalid error
If response.StatusCode <> HttpStatusCode.BadRequest Then
token = JsonConvert.DeserializeObject(Of TokenResponse)(response.Content)
Dim listViewResults As String = HttpGet(token.instance_url & "/services/data/v38.0/sobjects/Contact/listviews", "")
I am unsure whether this is a permission issue or more of a programming error; because in both cases all of the authentication strings are the same. At the moment I've hardcoded it to point to a test profile. So I can't pinpoint what exactly I am doing wrong?
Any help would suffice.
Stupid me,
Anyways shortly after I posted this I went and took a brisk walk outside of the office. Turned out to be a misnomer.
I had the same HttpGet method defined in the module file and forgot to copy and paste that into the class file. When I actually stepped through it, it threw an Exception inside.
Turned out the only fix needed was to put that method into the class file.
I have a website written in VB.NET that implements PayPal for payments. This is all working fine for successful payments, but I need to be able to simulate scenarios of a failed transaction, pending transaction, etc.
I have read the documentation, which starts on page 47. I enabled Negative Testing in a business account that I created in a Sandbox, but I am not getting desired results.
To simulate an error, as specified in the documentation, I'm passing an error code to Token, which is then used in a request to DoExpressCheckoutPayment - code below - but instead of this raising the error 10417, the response says Invalid Token:
Dim oldToken As String
With RequestDetails
oldToken = .Token
.Token = "10417"
End With
Dim request As New DoExpressCheckoutPaymentRequestType
request.DoExpressCheckoutPaymentRequestDetails = RequestDetails
Dim response As DoExpressCheckoutPaymentResponseType
response = DirectCast(caller.Call("DoExpressCheckoutPayment", request),
DoExpressCheckoutPaymentResponseType)
Questions:
What am I doing wrong in the code above so that I can't trigger a correct error?
How do I simulate a response where the status is Pending, Processed, Failed, etc.?
I was testing this about a week ago and was receiving the same problem, now, I no longer receive an error:
API Request:
METHOD=DoExpressCheckoutPayment
VERSION=82
token=10755
PayerID=GNT5WLV6WKLYW
PAYMENTACTION=Sale
AMT=456
PAYMENTREQUEST_0_AMT=458
PAYMENTREQUEST_0_ITEMAMT=458.00
PAYMENTREQUEST_0_SHIPPINGAMT=20.00
PAYMENTREQUEST_0_TAXAMT=46.20
PAYMENTREQUEST_0_CURRENCYCODE=USD
PAYMENTREQUEST_0_DESC=test EC payment
L_PAYMENTREQUEST_0_NAME0=Books
L_PAYMENTREQUEST_0_AMT0=154.00
L_PAYMENTREQUEST_0_NUMBER0=ABC123
L_PAYMENTREQUEST_0_QTY0=2
L_PAYMENTREQUEST_0_NAME1=CDs
L_PAYMENTREQUEST_0_AMT1=50.00
L_PAYMENTREQUEST_0_NUMBER1=BY-Z4736
L_PAYMENTREQUEST_0_QTY1=3
API Response:
TIMESTAMP=2011-09-27T20:39:57Z
CORRELATIONID=13126abeb4615
ACK=Failure
VERSION=82
BUILD=2133933
L_ERRORCODE0=10755
L_SHORTMESSAGE0=Unsupported Currency.
L_LONGMESSAGE0=Currency is not supported
L_SEVERITYCODE0=Error
I did find an article on x.com that deals with this issue as well.
I have recently developed and finished a software in which works like aim.
But here's the problem, the server worked just fine for local friends because they lived only 25 miles from the server, so it was lag-less.
But when uploaded to a web host, it lags every time it pings the server.
The server is in PHP, so there's no need to buy a dedicated computer for 400$/month more.
Here's the function in which the client constantly calls upon:
Public Function GetPage(ByVal url As String)
Dim WReq As HttpWebRequest
Dim WResp As WebResponse
Dim sr As IO.StreamReader
Try
WReq = WebRequest.Create(url)
WReq.CookieContainer = cookies
WReq.Timeout = "120000"
WResp = WReq.GetResponse()
sr = New IO.StreamReader(WResp.GetResponseStream())
GetPage = sr.ReadToEnd()
WResp.Close()
Return (GetPage)
Catch err As SystemException
MsgBox("err message: " & err.ToString & vbCrLf)
Catch ex As Exception
MsgBox("err message: " & ex.ToString & vbCrLf)
End Try
End Function
A demo url would be something like
http://localhost/chat/newpm.php?to=User&msg=Hello
So how does OSCAR do it (the platform for AOL, aka AIM)
and how does msg? gtalk or other big im clients do it?
I was thinking about recoding the getpage function so that it would connect to a TCP server and constantly wait for new messages which I am still not sure if this might cause a lag if the host is in the US and the client is not(for example).
Could you please provide me a remedy to this problem?
The Timeout is really high. Check if the app closes the connection after receive the response stream. How many aconnections the computer accepts otherwise the connectios will lock the request until one goes free.
Ok to answer John Feminella:
Exactly I agreee, how does AIM MSN and others solve this hang issue?
Dbasnett: return(GetPage) will return the result of the requested page, and this is just the main snipppet of the code which is called every second at least two times.
John Saunders:
I don't understand the purpose or function of the "using" blocks, I added the catch so that the user is not notified when the server times out or can't be resolved.
Sein Kraft:
Time out is only 2 minutes, i don't think it does
GetPage(Login.server & "pms.php?to=" & to)
That's all, then it would parse the results from the response.