Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

New Post: Suggestions on Async Operation where each Operation Could Have Different Credentials

$
0
0
I am not sure what you are attempting to do there but I think you are not using the async framework correctly.
An Async method returns a Task<Tweet> not a Tweet.

The async method is also returning directly and do not wait for the operation to complete.
If you are willing to do an operation on the Tweet, you need to await the operation to have completed (await the tweet has been created on twitter).

I think you are willing to do the following :
TwitterCredentials.ExecuteOperationWithCredentials(credentials, () =>
{
        var tweetTask = TweetAsync.PublishTweet("message");
        tweetTask.RunSynchronously();
        var tweet = tweetTask.Result;

        if (tweet == null)
        {
            logger.Error(string.Format("Twitter tweet of message for user id {0} failed, exception description: {1}, status code: {2}, details: {3}.", 
                accessToken, ExceptionHandler.GetLastException().TwitterDescription,
                ExceptionHandler.GetLastException().StatusCode, 
                ExceptionHandler.GetLastException().TwitterExceptionInfos.First().Message ));
            // just continue with notification processing and log errors about Twitter
        }
});
Though I think there is a missing feature here and you are right, invoking from an async method and leave right away would cause concurrency between the static credentials of the operation and the backup one.

I will be working on this as my next priority. It will be part of Tweetinvi 0.9.3.0 or potentially available as an update to 0.9.2.3.
A work item has been created here.

Regards,
Linvi

Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>