I'm using the OAuth method to access a ConstantContact user account. I can view contacts and lists, but when I try to create a new list via the REST API call it returns a 401 error. I'm using code from the ctctWrapper.php file to build the XML file. Is there any info I can use to see what I'm doing wrong?
Here's some code to show you what I'm doing and if there is something I'm doing wrong.
//Auth request with stored OAuth Creds
$list_api_request = OAuthRequest::from_consumer_and_token($oauth_consumer, $authorization_token, 'GET', $webServiceUrl.'lists');
$list_api_request->sign_request($sig_method, $oauth_consumer, $authorization_token);
//Send POST with XML to the lists REST API url
$list_request = curl_init($webServiceUrl.'lists');
curl_setopt($list_request, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($list_request, CURLOPT_HEADER, 0);
curl_setopt($list_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($list_request, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml", "accept:application/atom+xml", 'Content-Length: ' . strlen($listXML)));
curl_setopt($list_request, CURLOPT_FAILONERROR, 1);
curl_setopt($list_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($list_request, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($list_request, CURLOPT_POSTFIELDS, $listXML);
//Execute cURL request and get return.
$aero79_new_list = curl_exec($list_request);
$aero79_new_list = curl_getinfo($list_request);
$aero79_new_list = curl_error($list_request);
Problem seems to be around an error in creating the OAuth Authenticated URL. If you see this post in how to Authenticate using OAuth and PHP, you'll see that the OAuth request must be converted to a request URL that Curl can consume, otherwise this will fail. The change is actually two lines, see lines 7-8 below.