在C#中获取iCloud联系人列表 [英] Get iCloud Contact list in C#

查看:119
本文介绍了在C#中获取iCloud联系人列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索iCloud API之后,我在NodeJS和Python上找到了一些示例,但是不幸的是,我对它们并不熟悉。我想知道如何在C#上获取iCloud联系人列表。

After searching about iCloud API, I found some example on NodeJS and Python, but unfortunately, I'm not familiar with them. I want to know how to get iCloud Contact list on C#.

python上的示例: https://github.com/mindcollapse/iCloud-API/blob/master/iCloud.py
NodeJS上的示例: https://www.snip2code.com/Snippet/65033/Request-Contact -List-From-iCloud

Example on python: https://github.com/mindcollapse/iCloud-API/blob/master/iCloud.py Example on NodeJS: https://www.snip2code.com/Snippet/65033/Request-Contact-List-From-iCloud

我尝试将登录代码解析为C#:

I try to parse the login code to C#:

        private void iCloudLogin()
        {
            string guiid = Guid.NewGuid().ToString("N");
            //string url = "https://p12-setup.icloud.com/setup/ws/1/login?clientBuildNumber=1P24&clientId=" + guiid;
            string url = "https://setup.icloud.com/setup/ws/1/login?clientBuildNumber=1P24&clientId=" + guiid;

            using (var client = new WebClient())
            {
                client.Headers.Set("Origin", "https://www.icloud.com");
                client.Headers.Set("Referer", "https://www.icloud.com");
                client.Headers.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36");

                var values = new NameValueCollection();
                values["apple_id"] = appleId;
                values["password"] = password;
                values["extended_login"] = "false";

                var response = client.UploadValues(url, values);
            }
        }

我收到400:带有上述代码的错误请求,请帮助给出错误的方向,如果有代码示例,感谢您的帮助。

I receive 400 : Bad request with above code, please help to go give the direction where I'm wrong, I appreciate your help if there is code example.

更新:

现在我可以登录并获取许多信息,包括我的联系服务器URL,dsid,这是我使用的链接:

Now I could login and get many information, include my contact server url, dsid, this is the link I used:

https://p12-setup.icloud.com/setup/ws/1/ login?clientBuildNumber = 1P24& clientId = MyGuid

之后,我使用下面的网址获取联系人列表:

After that, I use below url to get contact list:

https://p35-contactsws.icloud.com/co/startup?clientBuildNumber=1P24&clientId=MyGuid&clientVersion=2.1&dsid=MyDSID&loc ale = zh-CN& order = last%2Cfirst

https://p35-contactsws.icloud.com 是我的联系服务器,它实际上是 https://p35-contactsws.icloud.com:443 ,但基于我所引用的示例,需要删除端口:443。

https://p35-contactsws.icloud.com is my contact server, it actually is https://p35-contactsws.icloud.com:443, but base on example I refer to, the port :443 need to be removed.

但我仍然收到421:客户端错误

But I still get 421: Client Error

推荐答案

我知道答案

首先,在这种情况下,请求应该是WebRequest,而不是WebClient。
在第一个api网址中: https: //setup.icloud.com/setup/ws/1/login?clientBuildNumber=WHATEVERNUMBER&clientId=RANDOM_GUID
WebRequest应该是一个Post,并在其中包含小程序,密码和标题应该是Origin = https://www.icloud.com

Firstly, in this case the request should be WebRequest, not WebClient. In the first api url: https://setup.icloud.com/setup/ws/1/login?clientBuildNumber=WHATEVERNUMBER&clientId=RANDOM_GUID : The WebRequest should be a Post and include appleid, password in data, and in header there should be Origin=https://www.icloud.com :

private void iCloudLogin() 
{        
    string data = "{\"apple_id\":" + appleId + ", \"password\":" + password + ", \"extended_login\":false}";
    byte[] dataStream = Encoding.UTF8.GetBytes(data);
    WebRequest webRequest = WebRequest.Create(url);
    webRequest.Method = "POST";
    webRequest.Headers.Set("Origin", "https://www.icloud.com");
    webRequest.ContentLength = dataStream.Length;
    Stream newStream=webRequest.GetRequestStream();
    // Attach the data.
    newStream.Write(dataStream,0,dataStream.Length);
    newStream.Close();
    WebResponse webResponse = webRequest.GetResponse();
    // get contact server url, dsid, Cookie
}

iCloud服务器将响应联系服务器的URL,dsid,以及 X-APPLE-WEBAUTH-TOKEN和 X-APPLE-WEBAUTH-USER(这两个值在webResponse的标题 Set-Cookie中)

iCloud server will response contact server url, dsid, also "X-APPLE-WEBAUTH-TOKEN" and "X-APPLE-WEBAUTH-USER" (these two values are in header "Set-Cookie" of webResponse)

如果您具有足够的上述参数,则可以获取icloud联系人列表,方法是:

When you have enough above parameters, you can get icloud contact list, follow by this way:

对此URL进行GET请求:
https://p35-contactsws.icloud.com/co/startup?clientBuildNumber=1P24&clientId=MyGuid&clientVersion=2.1&dsid=MyDSID&locale=zh-CN& order = last%2Cfirst

Make a GET request to this url: https://p35-contactsws.icloud.com/co/startup?clientBuildNumber=1P24&clientId=MyGuid&clientVersion=2.1&dsid=MyDSID&locale=en-EN&order=last%2Cfirst

+ https ://p35-contactsws.icloud.com :我的联系服务器网址,您的可以不同。

+https://p35-contactsws.icloud.com : my contact server url, yours can be different.

+ clien tVersion:仅需保留2.1

+clientVersion: just leave it 2.1

+ MyGuid:您在第一个请求中使用的向导。

+MyGuid: the Guid you used in the first request.

重要:标头中必须包含:

Important: in the header, must include:

来源: https:// www.icloud.com

Cookie:X-APPLE-WEBAUTH-TOKEN = XXXXXX; X-APPLE-WEBAUTH-USER = YYYYYYYYY

Cookie: X-APPLE-WEBAUTH-TOKEN=XXXXXX;X-APPLE-WEBAUTH-USER=YYYYYYYYY

在那之后,您将获得完整的iCloud联系人列表。

After that, you will get full iCloud Contact list.

这种方式是基于Web服务的,因此可以使用多种语言,所以我认为这会有所帮助。

This way is web service base, so it can work in many languages, so I think this can help.

这篇关于在C#中获取iCloud联系人列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆