Get iCloud Contact list in C#

◇◆丶佛笑我妖孽 提交于 2019-12-01 07:31:45
kairen

I know the answer

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 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)

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

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 : my contact server url, yours can be different.

+clientVersion: just leave it 2.1

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

Important: in the header, must include:

Origin:https://www.icloud.com

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

After that, you will get full iCloud Contact list.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!