6

最近V3にアップグレードしましたが、多くのことが壊れました

これらを修正するにはどうすればよいですか?

番号 1 :

Credentials や InMemoryCredentials などの定義がないため、これは機能しなくなりました。

var auth = new SingleUserAuthorizer
{
    Credentials = new InMemoryCredentials
    {
        ConsumerKey = srtwitterConsumerKey,
        ConsumerSecret = srtwitterConsumerSecret,
        OAuthToken = srtwitterOAuthToken,
        AccessToken = srtwitterAccessToken
        }
};

番号 2 : GetFileBytes の定義はもうありません

var mediaItems =
new List<Media>
{
    new Media
    {                 
        Data = Utilities.GetFileBytes(srImageUrl),
        FileName = srTweet.Split(' ')[0]+".jpg",
        ContentType = MediaContentType.Jpeg
    }
};

番号 3 : TweetWithMedia の定義なし

var tweet = twitterContext.TweetWithMedia(srTweet, false, mediaItems);

番号 4 : UpdateStatus の定義なし

var tweet = twitterContext.UpdateStatus(srTweet);

5 番 : CreateFavorite の定義がない

var vrResult = twitterContext.CreateFavorite(srRetweetId);

そして、V3の例が見つかりません

いつも言われますtwitterCtxが、そもそもどうやって手twitterCtxに入れるのですか?

4

1 に答える 1

9

LINQ to Twitter v3.0 は非同期です。これは、命名規則が変更され、一部のコードを呼び出す方法が変更されたことを意味します。一部の変更は、一貫性またはクロスプラットフォーム操作の改善のためのものです。また、複数のプラットフォームで実行できるポータブル クラス ライブラリ (PCL) でもあります。あなたの質問のいくつかの簡単な要約は次のとおりです。

  1. これを試して:

        var auth = new SingleUserAuthorizer
        {
            CredentialStore = new SingleUserInMemoryCredentialStore
            {
                ConsumerKey = ConfigurationManager.AppSettings["consumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"],
                AccessToken = ConfigurationManager.AppSettings["accessToken"],
                AccessTokenSecret = ConfigurationManager.AppSettings["accessTokenSecret"]
            }
        };
    
  2. GetFileBytes の以前の実装にはクロスプラットフォームの問題があるため、削除しました。ファイルのバイトを読み取るには、独自のコードを作成する必要があります。古い実装は次のとおりです。

    /// <summary>
    /// Reads a file into a byte array
    /// </summary>
    /// <param name="filePath">Full path of file to read.</param>
    /// <returns>Byte array with file contents.</returns>
    public static byte[] GetFileBytes(string filePath)
    {
        byte[] fileBytes = null;
    
        using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
        using (var memStr = new MemoryStream())
        {
            byte[] buffer = new byte[4096];
            memStr.Position = 0;
            int bytesRead = 0;
    
            while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
            {
                memStr.Write(buffer, 0, bytesRead);
            }
    
            memStr.Position = 0;
            fileBytes = memStr.GetBuffer();
        }
    
        return fileBytes;
    } 
    
  3. TweetWithMediaAsync オーバーロードの 1 つを次に示します。

        Status tweet = await twitterCtx.TweetWithMediaAsync(
            status, PossiblySensitive, Latitude, Longitude,
            PlaceID, DisplayCoordinates, imageBytes);
    
  4. これは TweetAsync と呼ばれるようになりました。

            var tweet = await twitterCtx.TweetAsync(status);
    
  5. CreateFavoriteAsync の例を次に示します。

        var status = await twitterCtx.CreateFavoriteAsync(401033367283453953ul);
    
  6. TwitterContext をインスタンス化する必要があります。例を次に示します。

        var twitterCtx = new TwitterContext(auth);
    

詳細については、ソース コードをダウンロードして、複数のテクノロジの実際の例を参照してください。サンプル プロジェクト名には、Linq2TwitterDemos_ プレフィックスが付いています。

https://linqtotwitter.codeplex.com/SourceControl/latest#ReadMe.txt

すべての API 呼び出しが文書化されているだけでなく、LINQ to Twitter の他の側面に関する文書も記載されています。

https://linqtotwitter.codeplex.com/documentation

于 2014-03-21T18:34:47.147 に答える