private void GetRequestTokenCallback(APICallbackArgs acArgs) { if (RequestTokenReceived != null) { OAuthResponseObject oroResponse = (OAuthResponseObject)acArgs.ResponseObject; if (acArgs.Succeeded) { if (oroResponse.Response.ContainsKey("oauth_token") && oroResponse.Response.ContainsKey("oauth_token_secret")) { oroResponse.Credentials.Token = oroResponse.Response["oauth_token"]; oroResponse.Credentials.TokenSecret = oroResponse.Response["oauth_token_secret"]; APIReturn.SynchronizeInvoke(RequestTokenReceived, new object[4] { this, true, "", oroResponse.Credentials }); } else { APIReturn.SynchronizeInvoke(RequestTokenReceived, new object[4] { this, false, "An error occurred retrieving a request token from Twitter. Please try again.", null }); } } else { APIReturn.SynchronizeInvoke(RequestTokenReceived, new object[4] { this, false, acArgs.ErrorMessage, null }); } } }
private void GetAccessTokenCallback(APICallbackArgs acArgs) { if (AccessTokenReceived != null) { OAuthResponseObject oroResponse = (OAuthResponseObject)acArgs.ResponseObject; if (acArgs.Succeeded) { if (oroResponse.Response.ContainsKey("oauth_token") && oroResponse.Response.ContainsKey("oauth_token_secret")) { oroResponse.Credentials.Token = oroResponse.Response["oauth_token"]; oroResponse.Credentials.TokenSecret = oroResponse.Response["oauth_token_secret"]; oroResponse.Credentials.ClientUsername = oroResponse.Response["screen_name"]; APIReturn.SynchronizeInvoke(AccessTokenReceived, new object[4] { this, true, "", oroResponse.Credentials }); } else { APIReturn.SynchronizeInvoke(AccessTokenReceived, new object[4] { this, false, "An error occurred authenticating with the pin you supplied. Please try again with the correct pin.", null }); } } else { APIReturn.SynchronizeInvoke(AccessTokenReceived, new object[4] { this, false, acArgs.ErrorMessage, null }); } } }
private void MentionsCallback(APICallbackArgs acArgs) { UserTimeline utInitial = (UserTimeline)acArgs.ResponseObject; for (int i = utInitial.Statuses.Count - 1; i >= 0; i--) { APIReturn.SynchronizeInvoke(Receive, new object[] { this, new JsonDocument(utInitial.Statuses[i].Object), ReceiveType.Reply }); } EstablishStream(); }
private void HomeTimelineCallback(APICallbackArgs acArgs) { UserTimeline utInitial = (UserTimeline)acArgs.ResponseObject; for (int i = utInitial.Statuses.Count - 1; i >= 0; i--) { APIReturn.SynchronizeInvoke(Receive, new object[] { this, new JsonDocument(utInitial.Statuses[i].Object), ReceiveType.Tweet }); } m_bscAPI.GetMentions(MentionsCallback, null); }
private void RequestCallback(RestRequest rrqRequest, RestResponse rrsResponse, object objUserState) { try { StreamReader srReader = new StreamReader(rrsResponse.ContentStream, Encoding.UTF8); string sCurLine; do { sCurLine = srReader.ReadLine().Trim(); } while ((sCurLine == "") && (!srReader.EndOfStream)); JsonDocument jdFinal = JsonParser.GetParser().ParseString(sCurLine); if (jdFinal != null) { if (jdFinal.Root.IsNode()) { if (jdFinal.Root.ToNode().ContainsKey("friends")) { //this is the friends list that's sent at the beginning of each userstream connection APIReturn.SynchronizeInvoke(Receive, this, jdFinal, ReceiveType.FriendsList); } else if (jdFinal.Root.ToNode().ContainsKey("retweeted")) { Status stNewStatus = new Status(jdFinal.Root.ToNode()); if (stNewStatus.IsReply && stNewStatus.ReplyNames.Contains(m_oaCredentials.ClientUsername)) { APIReturn.SynchronizeInvoke(Receive, this, jdFinal, ReceiveType.Reply); } else { APIReturn.SynchronizeInvoke(Receive, this, jdFinal, ReceiveType.Tweet); } } else if (jdFinal.Root.ToNode().ContainsKey("recipient_id") && jdFinal.Root.ToNode().ContainsKey("sender_id")) { DirectMessage dmNewMessage = new DirectMessage(jdFinal.Root.ToNode()); APIReturn.SynchronizeInvoke(Receive, this, jdFinal, ReceiveType.DirectMessage); } //also need to add OnDelete for when a tweet gets deleted } } } catch (Exception e) { MessageBox.Show("An unknown Twitter API error has occurred (user streams). " + e.Message, "API Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void GetUserObjectCallback(APICallbackArgs acArgs) { List <User> luResponseList = (List <User>)acArgs.ResponseObject; if (luResponseList.Count > 0) { m_uUserObject = luResponseList[0]; if (UserObjectReceived != null) { APIReturn.SynchronizeInvoke(UserObjectReceived, this, EventArgs.Empty); } } }
private void DoRequestCallback(RestRequest rrqRequest, RestResponse rrsResponse, object objUserState) { RestResponseHash rrhResponse = new RestResponseHash(rrsResponse); APIReturn aprReturn = (APIReturn)objUserState; OAuthCredentials oaCredentials = (OAuthCredentials)aprReturn.CallbackArg; string sErrorMessage = ""; if (rrsResponse.InnerException != null) { sErrorMessage = rrsResponse.InnerException.Message; } APICallbackArgs acArgs = new APICallbackArgs(rrsResponse.StatusCode == HttpStatusCode.OK, sErrorMessage, new OAuthResponseObject(rrhResponse, oaCredentials)); aprReturn.SynchronizeInvoke(new object[] { acArgs }); }
protected void DoRequestCallback(RestRequest rrqRequest, RestResponse rrsResponse, object objUserState) { try { //StreamWriter swWriter = new StreamWriter("C:/Users/le grand fromage/Desktop/tweets.json", true, Encoding.UTF8); //StreamReader srReader = new StreamReader(rrsResponse.ContentStream, Encoding.UTF8); //swWriter.WriteLine(srReader.ReadToEnd()); //swWriter.Close(); //return; JsonDocument jsDoc = JsonParser.GetParser().ParseStream(new StreamReader(rrsResponse.ContentStream, Encoding.UTF8)); APIReturn aprReturn = (APIReturn)objUserState; object objToReturn = null; string sErrorMessage = ""; APICallbackArgs acArgs; if (jsDoc.Root.IsNode() && jsDoc.Root.ToNode().ContainsKey("error")) { sErrorMessage = jsDoc.Root.ToNode()["error"].ToString(); } else if (rrsResponse.InnerException != null) { sErrorMessage = rrsResponse.InnerException.Message; } if (aprReturn.ReturnType != null) { if (jsDoc.Root.IsList()) { //if the return type is a generic list... if (aprReturn.ReturnType.Name == "List`1") { //get an instance of the list<generic> that will have generics added to it and eventually be returned via the callback //get the type of the generic (because we'll need to make specific instances of him later) objToReturn = System.Activator.CreateInstance(aprReturn.ReturnType); Type tListObjType = aprReturn.ReturnType.GetGenericArguments()[0]; //dynamically invoke the Add() method of the list //what's being added: a newly minted instance of the generic class plus data via the constructor foreach (JsonObject joCur in jsDoc.Root.ToList()) { aprReturn.ReturnType.GetMethod("Add").Invoke(objToReturn, new Object[] { System.Activator.CreateInstance(tListObjType, joCur.ToNode()) }); } } else { objToReturn = System.Activator.CreateInstance(aprReturn.ReturnType, jsDoc.Root.ToList()); } } else if (jsDoc.Root.IsNode()) { objToReturn = System.Activator.CreateInstance(aprReturn.ReturnType, jsDoc.Root.ToNode()); } } acArgs = new APICallbackArgs(rrsResponse.StatusCode == HttpStatusCode.OK, sErrorMessage, objToReturn); aprReturn.SynchronizeInvoke(new object[] { acArgs }); //synchronously invoke the return callback } catch (Exception e) { MessageBox.Show("An unknown Twitter API error has occurred (basic).", "API Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }