String status;
IEnumerable<TwitterStatus> twitterStatus = twitterService.ListTweetsOnPublicTimeline();
foreach(String status in twitterStatus)
{
Console.WriteLine(twitterStatus);
}
为什么它给出了 foreach 循环中不能转换字符串类型的错误?这是我的全部代码
namespace TweetingTest
{
class Program
{
static void Main(string[] args)
{
TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
twitterClientInfo.ConsumerKey = ConsumerKey; //Read ConsumerKey out of the app.config
twitterClientInfo.ConsumerSecret = ConsumerSecret; //Read the ConsumerSecret out the app.config
TwitterService twitterService = new TwitterService(twitterClientInfo);
if (string.IsNullOrEmpty(AccessToken) || string.IsNullOrEmpty(AccessTokenSecret))
{
//Now we need the Token and TokenSecret
//Firstly we need the RequestToken and the AuthorisationUrl
OAuthRequestToken requestToken = twitterService.GetRequestToken();
string authUrl = twitterService.GetAuthorizationUri(requestToken).ToString();
//authUrl is just a URL we can open IE and paste it in if we want
Console.WriteLine("Please Allow This App to send Tweets on your behalf");
//Process.Start(authUrl); //Launches a browser that'll go to the AuthUrl.
//Allow the App
Console.WriteLine("Enter the PIN from the Browser:");
string pin = Console.ReadLine();
OAuthAccessToken accessToken = twitterService.GetAccessToken(requestToken, pin);
string token = accessToken.Token; //Attach the Debugger and put a break point here
string tokenSecret = accessToken.TokenSecret; //And another Breakpoint here
Console.WriteLine("Write Down The AccessToken: " + token);
Console.WriteLine("Write Down the AccessTokenSecret: " + tokenSecret);
}
twitterService.AuthenticateWith(AccessToken, AccessTokenSecret);
//Console.WriteLine("Enter a Tweet");
//string tweetMessage;
//string data;
//string ListTweetsOnPublicTimeline;
//string TwitterUserStreamStatus = ListTweetsOnPublicTimeline();
//TwitterStatus=ListTweetsOnPublicTimeline();
//tweetMessage = Console.ReadLine();
//ListTweetsOnPublicTimeline = Console.ReadLine();
//TwitterStatus twitterStatus = twitterService.SendTweet(tweetMessage);
//TwitterStatus twitterStatus = twitterService.ListTweetsOnPublicTimeline();
//String status;
IEnumerable<TwitterStatus> tweets = twitterService.ListTweetsOnPublicTimeline();
foreach(var tweet in tweets)
{
Console.WriteLine(tweet);
//Console.WriteLine("{0} says '{1}'", tweet.User.ScreenName, tweet.Text);
}
//twitterStatus=Console.ReadLine();
}
这是我正在处理的整个代码,并且在 foreach 循环中只遇到一个错误,这是我缺乏 C# 知识