2017-12-15 7 views
0

Coinbaseアカウントのウォレットのリストを取得する必要があります。そのためには、API秘密鍵を使用してRestSharp(3番目のライブラリは許可されていません)を使用する必要があります。RestSharpライブラリを使用したCoinbaseウォレットリストの取得

は、私はそれらを取得しようとしましたが、私は、コードを実行すると、応答として私は

を言うエラーメッセージが表示され、無効な応答を得る「URIプレフィックスが認識されていません。」

ウォレットのリストはどのように取得できますか?

これは私のコードです:

using RestSharp; 
using System; 
using System.IO; 
using System.Linq; 
using System.Security.Cryptography; 
using System.Text; 

namespace WCoinBase 
{ 
    class Program 
    { 

    private const string apiKey = "MyPrivateKey"; 

    static void Main(string[] args) 
    { 
     RestClient restClient = new RestClient 
     { 
     BaseUrl = new Uri("https://api.coinbase.com/v2/") 
     }; 
     string timestamp = DateTimeOffset.Now.ToUnixTimeSeconds().ToString(); 
     string path = "wallet:accounts:read"; 
     var request = new RestRequest 
     { 
     Method = Method.GET, 
     Resource = path 
     }; 
     string accessSign = GetAccessSign(timestamp, "GET", path, ""); 
     request.AddHeader("CB-ACCESS-KEY", apiKey); 
     request.AddHeader("CB-ACCESS-SIGN", accessSign); 
     request.AddHeader("CB-ACCESS-TIMESTAMP", timestamp); 
     request.AddHeader("CB-VERSION", "2017-08-07"); 
     request.AddHeader("Accept", "application/json"); 
     var response = restClient.Execute(request); 
     Console.WriteLine("Status Code: " + response.StatusCode); 

    } 

    static private string GetAccessSign(string timestamp, string command, string path, string body) 
    { 
     var hmacKey = Encoding.UTF8.GetBytes(apiKey); 

     string data = timestamp + command + path + body; 
     using (var signatureStream = new MemoryStream(Encoding.UTF8.GetBytes(data))) 
     { 
     var hex = new HMACSHA256(hmacKey).ComputeHash(signatureStream) 
      .Aggregate(new StringBuilder(), (sb, b) => sb.AppendFormat("{0:x2}", b), sb => sb.ToString()); 

     return hex; 
     } 
    } 
    } 
} 

答えて

2

あなたはこのエラーを取得している理由は、URLが有効なURLではありませんhttps://api.coinbase.com/v2/wallet:accounts:read、として構成されています。

スコープをパスとして設定していますが、これは間違っています。

あなたが打つべきであるGET https://api.coinbase.com/v2/accounts

参照:https://developers.coinbase.com/api/v2#list-accounts

パスは、 "アカウント"、ではないwallet:accounts:readでなければなりません。

スコープに関する文書はhereです。

+0

私は 'wallet:accounts:read'コマンドをどこに置く必要がありますか? – Jepessen

+0

これはコマンドではありません。これは、資格情報に追加する権限の有効範囲です。 https://developers.coinbase.com/docs/wallet/permissions。 – Amy

関連する問題