I am trying to get TweetSharp to search with twitter. It always returns null. There is no error or other information. I setup my consumerkey, consumer secret, access token, and token secret
Here is my code:
TwitterService service = new TwitterService(consumerKey, consumerSecret);
service.AuthenticateWith(accessToken, tokenSecret);
SearchOptions options = new SearchOptions { Q = "#VeternsDay", Count = 100, Resulttype = TwitterSearchResultType.Recent };
TwitterSearchResult searchedTweets = service.Search(options);
return searchedTweets;
I know this question is old, but I was playing around C# and Tweetsharp and saw your question and tried to solve it :)
I tried to recreate your example and I got it working! You needed to loop over the searchedTweets.Statuses and get their contents. In this example I got the 100 popular tweets in the #Bahrain hashtag and got those tweets username authors.
var service = new TwitterService(consumerKey, consumerSecret);
service.AuthenticateWith(accessToken, accessTokenSecret);
SearchOptions options = new SearchOptions { Q = "#Bahrain", Count = 100, Resulttype = TwitterSearchResultType.Popular};
TwitterSearchResult searchedTweets = service.Search(options);
foreach(var tweet in searchedTweets.Statuses)
{
MessageBox.Show( tweet.Author.ScreenName);
}
Related
I'm trying to download captions from some videos on Youtube using their nuget package. Here's some code:
var request = _youtube.Search.List("snippet,id");
request.Q = "Bill Gates";
request.MaxResults = 50;
request.Type = "video";
var results = request.Execute();
foreach (var result in results.Items)
{
var captionListRequest = _youtube.Captions.List("id,snippet", result.Id.VideoId);
var captionListResponse = captionListRequest.Execute();
var russianCaptions =
captionListResponse.Items.FirstOrDefault(c => c.Snippet.Language.ToLower() == "ru");
if (russianCaptions != null)
{
var downloadRequest = _youtube.Captions.Download(russianCaptions.Id);
downloadRequest.Tfmt = CaptionsResource.DownloadRequest.TfmtEnum.Srt;
var ms = new MemoryStream();
downloadRequest.Download(ms);
}
}
When the Download method is called I'm getting a weird Newtonsoft.JSON Exception that says:
Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: T. Path '', line 0, position 0.'
at Newtonsoft.Json.JsonTextReader.ParseValue()
I've read some other threads on captions downloading problems and have tried to change my authorization workflow: first I've tried to use just the ApiKey but then also tried OAuth. Here's how it looks now:
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "CLIENT_ID",
ClientSecret = "CLIENT_SECRET"
},
new[] { YouTubeService.Scope.YoutubeForceSsl },
"user",
CancellationToken.None,
new FileDataStore("Youtube.CaptionsCrawler")).Result;
_youtube = new YouTubeService(new BaseClientService.Initializer
{
ApplicationName = "LKS Captions downloader",
HttpClientInitializer = credential
});
So, is it even possible to do what I'm trying to achieve?
P.S. I was able to dig deep into the youtube nuget package and as I see, the actual message, that I get (that Newtonsoft.JSON is trying to deserialize, huh!) is "The permissions associated with the request are not sufficient to download the caption track. The request might not be properly authorized, or the video order might not have enabled third-party contributions for this caption."
So, do I have to be the video owner to download captions? But if so, how do other programs like Google2SRT work?
Found this post How to get "transcript" in youtube-api v3
You can get them via GET request on: http://video.google.com/timedtext?lang={LANG}&v={VIDEOID}
Example:
http://video.google.com/timedtext?lang=en&v=-osCkzoL53U
Note that they should have subtitles added, will not work if auto-generated.
I Want use telegram api bot . every thing is ok (in my idea) but i have stupid error that where ever is search i cant find any thing .
I am using Inline mode .
var awnser = new AnswerInlineQuery()
{
inline_query_id =model.inline_query.id,
results = new List<InlineQueryResultArticle>()
};
awnser.results.Add(new InlineQueryResultArticle() { id = Guid.NewGuid().ToString("N"), type = "article", url = "fidilio", input_message_content = new InputTextMessageContent() { message_text = "salam" }, title = "test" });
var send = SendInlineAwnser(awnser);
The send method is using restsharp
var ser = JsonConvert.SerializeObject(data);
var url = "https://api.telegram.org/bot" + telegramToken + "/answerInlineQuery";
var req = SimplePost<AnswerInlineQuery>(ser, url);
my serlization out put is this
{"inline_query_id":"302418856930797437","results":[{"type":"article","id":"fae56651b23244f8a3be94b1e6ebf6e7","title":"test","input_message_content":{"message_text":"salam"},"url":"fidilio"}]}
make sure that model.inline_query.id is correct and if so, keep in mind that you can send notify max 15 sec after inline keyboard pushed. Besides, I suggest using async method for sending inline query results.
I would like to execute a query on google images to fetch images using htmlagilitypack in c#.
For this I used an xpath request to the image
//*[#id="rg_s"]/div[1]/a/img
But it fails to fetch the image that way. What could be the correct way of doing this?
you can try this too : Here its possible to get the links of images by following
var links = HtmlDocument.DocumentNode.SelectNodes("//a").Where(a => a.InnerHtml.Contains("<img")).Select(b => b.Attributes["href"].Value).ToList();
foreach(var link in links)
{
// you can save the link or do your process here
}
Google keeps found images in div tags with class rg_di. Here is a query to get all links to images:
var links = hdoc.DocumentNode.SelectNodes(#"//div[#class='rg_di']/a")
.Select(a => a.GetAttributeValue("href", ""));
Searching google programmatically outside of their API's is against the TOS. Consider Google Custom Search or Bing Search API, both of which have established JSON and SOAP interfaces.
Both are free for a couple thousand queries per month and comply with the service's TOS.
Edit: Examples of using Bing API with C# below:
const string bingKey = "[your key here]";
var bing = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/"))
{
Credentials = new NetworkCredential(bingKey, bingKey)
};
var query = bing.Web("Jon Gallant blog", null, null, null, null, null, null, null);
var results = query.Execute();
foreach(var result in results)
{
Console.WriteLine(result.Url);
}
Console.ReadKey();
Google custom search API:
string apiKey = "Your api key";
string cx = "Your custom search engine id";
string query = "Your query";
var svc = new Google.Apis.Customsearch.v1.CustomsearchService(new BaseClientService.Initializer { ApiKey = apiKey });
var listRequest = svc.Cse.List(query);
listRequest.Cx = cx;
var search = listRequest.Fetch();
foreach (var result in search.Items)
{
Response.Output.WriteLine("Title: {0}", result.Title);
Response.Output.WriteLine("Link: {0}", result.Link);
}
I try to get the last 20 statuses of the Usertimeline. So I search in the internet and get
the follow code:
TwitterUser twitterUser = TwitterUser.Show("Username").ResponseObject;
if (twitterUser != null)
{
UserTimelineOptions userTimelineOptions = new UserTimelineOptions();
userTimelineOptions.UserId = twitterUser.Id;
return TwitterTimeline.UserTimeline(userTimelineOptions).ResponseObject;
}
return null;
When I test it, I get the follow exception:
Unexpected token when deserializing object: StartObject. Line 1, position 1795.
I have no idea what's wrong so I hope you can help me!
Since Twitterizer is discontinued, I assumed that you moved to TweetSharp:
TwitterService service = new TwitterService("consumerKey", "consumerSecret");
service.AuthenticateWith("accessToken", "accessTokenSecret");
var options = new ListTweetsOnHomeTimelineOptions();
options.ExcludeReplies = true;
var tweets = service.ListTweetsOnHomeTimeline(options);
For Twitterizer:
UserTimelineOptions options = new UserTimelineOptions();
options.ScreenName = "Username";
var tweets = TwitterTimeline.UserTimeline(options).ResponseObject;
Twitterizer uses the 1.0 API and TweetSharp has the required oAuth for the 1.1 twitter API:
https://dev.twitter.com/blog/changes-coming-to-twitter-api
Try this
var twitterService = new TwitterService("consumerKey", "consumerSecret");
twitterService.AuthenticateWith("token", "tokenSecret");
var tweets = twitterService.ListTweetsOnHomeTimeline();
I tried this:
oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
oAuthClient.RedirectUri = callBack;
var parameters = new Dictionary<string, object>();
parameters.Add("permissions", "offline_access,publish_stream");
var loginUri = oAuthClient.GetLoginUrl(parameters);
this brings me the access token , i save it in Database
now i try to post to facebook doing this :
var postparameters = new Dictionary<string, object>();
postparameters["message"] = tweet;
postparameters["name"] = "This is a name";
_fbClient = new FacebookClient(accessToken);
var result = _fbClient.Post("/me/feed", postparameters);
problem is this tells me that im not authorized to post. so in order to make it work i have to visit this url :
http://www.facebook.com/authorize.php?api_key=[key]&v=1.0&ext_perm=publish_stream
this also have a problem cause this link doesnt redirect back !
so the question is how i do get the access token from the first place with the publish_stream permission?
change
parameters.Add("permissions", "offline_access,publish_stream");
to
parameters.Add("scope", "offline_access,publish_stream");