Twitter 通过 API 刷新页面

发布于 2024-08-25 03:49:03 字数 129 浏览 5 评论 0原文

我正在使用 Twitter API(通过 TweetSharp),想知道是否可以通过 API 自动刷新页面以便所有用户都能看到更新?如果是这样,是否也可以更进一步,仅更新部分页面,以便仅更新相关更改而不是整个页面?

感谢您的帮助

I'm using the Twitter API (via TweetSharp) and was wondering if it's possible to automatically refresh the page from the API so that all users see the update? If so, is it also possible to take it one step further by only have a partial page update so only the relevant change is updated instead of the entire page?

Thanks for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

呆头 2024-09-01 03:49:03

我想我理解你的问题,你想显示一堆用户和他们的最后一条推文 - 但要继续检查他们的最后一条推文是否已更改并在用户发布推文时更新屏幕?

如果是这样,答案是您需要经常异步调用 twitterapi 并下拉每个用户的最后状态(推文) - 如果它是新用户,则使用 ajax 将屏幕部分更新为旧状态(推文)在其中。

在 TweetSharp 中,如果您有朋友列表,您可以使用以下内容拉取他们的最后一条推文:

    string profileImageUrl = String.Empty;
    string name = String.Empty;
    string statusText = String.Empty;
    string createdAt = String.Empty;
    string screenName = String.Empty;

    foreach (TwitterUser friend in friends)
    {
        try
        {
            profileImageUrl = String.IsNullOrEmpty(friend.ProfileImageUrl) ? "" : friend.ProfileImageUrl;
            name = String.IsNullOrEmpty(friend.Name) ? "" : friend.Name;
            statusText = (friend.Status == null || friend.Status.Text.Length == 0) ? "unknown" : friend.Status.Text; //stops nullreferenceexception on instance
            createdAt = String.IsNullOrEmpty(friend.CreatedDate.ToString()) ? "" : friend.CreatedDate.ToString();
            screenName = String.IsNullOrEmpty(friend.ScreenName) ? "" : friend.ScreenName;
        }
        catch (NullReferenceException)
        {
            profileImageUrl = "";
            name = "unknown";
            statusText = "unknown";
            createdAt = "";
            screenName = "unknown";

这样您就可以首先将其显示在屏幕上。

然后使用jquery(或javascript)定期 点击一个读取 twitter api 的 Web 服务,然后使用返回的数据来更新最后一条推文(如果它发生了变化)。

如果我的做法有误,请告诉我。

编辑:

使用 Tweetsharp 向 Twitter 发布新推文的示例如下:

var query = FluentTwitter.CreateRequest().AuthenticateAs(username,password).Statuses().Update("Posting status on StackOverflow").AsJson();

I think I understand your question, that you want to display a bunch of users and their last tweet - but keep checking if their last tweet has changed and update the screen when the user posts a tweet?

If so the answer is that you need to call the twitterapi asynchronously every so often and pull down the last status (tweet) for each user - and if it is a new one then use ajax to update the part of the screen with the old status (tweet) in it.

In TweetSharp if you have a List of friends, you can pull in their last tweet with something like:

    string profileImageUrl = String.Empty;
    string name = String.Empty;
    string statusText = String.Empty;
    string createdAt = String.Empty;
    string screenName = String.Empty;

    foreach (TwitterUser friend in friends)
    {
        try
        {
            profileImageUrl = String.IsNullOrEmpty(friend.ProfileImageUrl) ? "" : friend.ProfileImageUrl;
            name = String.IsNullOrEmpty(friend.Name) ? "" : friend.Name;
            statusText = (friend.Status == null || friend.Status.Text.Length == 0) ? "unknown" : friend.Status.Text; //stops nullreferenceexception on instance
            createdAt = String.IsNullOrEmpty(friend.CreatedDate.ToString()) ? "" : friend.CreatedDate.ToString();
            screenName = String.IsNullOrEmpty(friend.ScreenName) ? "" : friend.ScreenName;
        }
        catch (NullReferenceException)
        {
            profileImageUrl = "";
            name = "unknown";
            statusText = "unknown";
            createdAt = "";
            screenName = "unknown";

So you can display it on the screen initially.

Then use jquery (or javascript) to periodically hit a web service that reads the twitter api and then use the data returned to update the last tweet if it has changed.

Let me know if I have the wrong end of the stick.

EDIT:

An example of using Tweetsharp posting a new tweet to Twitter is:

var query = FluentTwitter.CreateRequest().AuthenticateAs(username,password).Statuses().Update("Posting status on StackOverflow").AsJson();
陈年往事 2024-09-01 03:49:03

我不使用这个 dll,但我正在编写一个,并且 Twitter API 期望您再次调用 - 据我所知,没有刷新。如果这个 dll 允许您从某个日期开始查询,那么这是可能的,并且可能是调用的参数。我希望这有一点帮助

I dont use this dll, but I am writing one, and the Twitter API expects you to call again - there is no refresh as I know. If this dll allows you to query since a date then that is possilbe and would probably be a parameter to the call. I hope this helps a little

往事随风而去 2024-09-01 03:49:03

If you're using ASP .NET you could consider using AJAX with the UpdatePanel control. It would probably be the easiest way to get what you need with ASP .NET

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文