3

私は友人/ID呼び出しを次のように発行しています:

GET /1.1/friends/ids.json?screen_name=blablabla HTTP/1.1

有効な応答が発行されます。

{"ids":[97500486,32947624,8884440,2022687,28741369,33978239,10312111,950922,7682036,21688137,7696145,15876098],"next_cursor":0,"next_cursor_str":"0","previous_cursor":0,"previous_cursor_str":"0"}

私のインターフェースは次のようになります。

[OperationContract(Name = "ids.json")]
[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate="ids.json?user_id={userId}&screen_name={screenName}")]
FriendsIdsResponse Ids(long? userId, string screenName);

[DataContract]
public class FriendsIdsResponse
{
  public FriendsIdsResponse()
  {
  }

  [DataMember(Name = "ids")]
  public long[] Ids { get; set; }
  [DataMember(Name = "previous_cursor")]
  public int PreviousCursor { get; set; }
  [DataMember(Name = "next_cursor")]
  public int NextCursor { get; set; }
}

ID の型 (long[]、IList、List など) に関係なく、常に null が返されます。ctor で空のリストにインスタンス化すると、Count==0 になります。

要求に応じて、WCF 構成を更新します。

<system.serviceModel>
    <client>
        <endpoint contract="TA.Twitter.Service.IFriends, TA.Twitter.Interfaces"
                            address="https://api.twitter.com/1.1/friends/"
                            binding="webHttpBinding" bindingConfiguration="WebHttpBinding"
                            ></endpoint>
    </client>
    <bindings>
        <webHttpBinding>
            <binding name="WebHttpBinding" allowCookies="true">
                <security mode="Transport">
                </security>
            </binding>
        </webHttpBinding>
    </bindings>
</system.serviceModel>
4

1 に答える 1

1

完全な答えではありませんが、WCF を使用して Tweeter API を呼び出すように制限されていますか? 私は WCF の大ファンですが、Twitter には既に多くの .net ライブラリがあります。WCF には課題があることは理解していますが、毎回車輪を再発明することは避けたいと思っています。

Tweetsharpは、Twitter API アクセス用の一般的な .net ライブラリのようです。

既に OAuth トークンを持っていると仮定すると、get friends は 10 行未満のコードで完了します。

    var service = new TweetSharp.TwitterService("consumerKey", "consumerSecret");
    service.AuthenticateWith("accessToken", "accessTokenSecret");

    var friends = service.ListFriendIdsOf(new TweetSharp.ListFriendIdsOfOptions() { ScreenName = "blabla" });
    foreach (var friend in friends)
    {
        Console.WriteLine("new friend :{0} ", friend);
    } 

10 行未満、10 分未満が適切な妥協点のようです

于 2013-06-12T12:10:23.393 に答える