Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Contact List From ICloud API

Requesting ICloud API and login by using below URL

string url = "https://setup.icloud.com/setup/ws/1/login?clientBuildNumber=1P24&clientId=" + RANDOM_GUID;

Getting server url and dsid from above url response. Further requesting for Contact list by using below code

var localUrl2 = "https://p66-contactsws.icloud.com/co/startup?clientBuildNumber=1P24&clientId=" + RANDOM_GUID + "&clientVersion=2.1&dsid=" + dsid + "&locale=en-EN&order=last%2Cfirst";
var webRequest2 = (HttpWebRequest)WebRequest.Create(localUrl2);
webRequest2.Method = "GET";
webRequest2.Headers.Set("Origin", "https://www.icloud.com");
// get the X-APPLE-WEBAUTH-TOKEN and X-APPLE-WEBAUTH-USER from  webResponse.Headers.SetCookie
webRequest2.Headers.Set("X-APPLE-WEBAUTH-TOKEN",  XXXXXXX);
webRequest2.Headers.Set("X-APPLE-WEBAUTH-USER",  XXXXXXXX);

WebResponse webResponse2 = webRequest2.GetResponse();

Still getting exception

The remote server returned an error: (421) Misdirected Request.

Please let me know what is wrong in above code.

like image 268
Imtiaz Ahmed Avatar asked Aug 01 '18 09:08

Imtiaz Ahmed


People also ask

How do I pull my contacts from iCloud?

Can I view my contacts on iCloud from Android devices? You can go to iCloud.com on your Android browser and access all the contacts synced to your iCloud account.

Does Apple iCloud have an API?

iCloud Storage APIs allow you to store your app's data in iCloud. System services sync your data automatically even when your app isn't running.


1 Answers

As mentioned in the comments, Apple has taken the end point you are trying to reach offline hence the 421 error. You can look into another way to accomplish this here.

like image 94
James Avatar answered Oct 27 '22 13:10

James