I am using Ning API in PHP to retrieve list of photos.

 

I have three queries:

 

1) The response obtained using the API does not provide any URL for the photo. How am I suppose to show the preview (or may be a thumbnail) for the photos of the user.

 

2) I believe the API should return the list of the photos of the user whose credentials are used to login. However, the API returns the list of photos of other users as well. I am missing something or this is the functionality implemented in this way.

 

3) When I use the Consumer Key and secret key to login and retrieve the access tokens, I am unable to retrieve the list of photos using the obtained access tokens for any subsequent requests i.e. I require to login for every request.

 

Thanks.

Mahendra.

Views: 710

Reply to This

Replies to This Discussion

Great questions, I hope these answers help:

 

1) The Ning API requires you to specifically request the data fields you need, this is done with the fields parameter. To return the photo's image URL, you need to request the 'image.url' field in the fields request parameter. An example URL would be:

GET https://<BASE_URL>/Photo/recent?fields=title,description,image.url,image.width,image.height

 

2) By default /Photo/recent returns photos from all members. You can filter the result for a particular member by using the 'author' query parameter. For example:

GET https://<BASE_URL>/Photo/recent?author=3ixs6bzjxfkv6

Where '3ixs6bzjxfkv6' is the ID of your member. You can figure out the member's author ID by querying the User endpoint. For example:

GET https://<BASE_URL>/User?fields=author

 

3) If I understand you correctly, you are able to make one successful request with a pair of access tokens, but subsequent requests do not work? You should only need to request the access tokens once per member. What is the specific error response you receive?

Hello Devin,

Firstly, thank you for taking time to reply my question.

I tried testing with your suggestion. However, to my surprise my earlier code which was working and giving results now shows an oauth error.

The error is : "Fatal error: Uncaught The oauth_timestamp value is unacceptable to the Service Provider. The timestamp of the request must be within 300 seconds of the current time Acceptable range: 1301732382-1301732983 (401) 1-14 thrown in C:\wamp\www\ning\NingException.php on line 56"

 

Do you have any idea about this error?

 

Thanks,

Mahendra.

This error is generally caused when your local computer's time is more than five minutes off. I believe Windows has an option to update the time via the Internet. Try that option or try manually updating it.

The server disregards any old requests and uses the oauth_timestamp parameter to determine it.

Hey Devin,

 

The oauth error got solved. Yes, may be it was a time difference error.

 

Referring to question no. 3 asked by me, the details are like this.

 

I use my email address and password along with the consumer key and consumer secret. This returns me access token and access secret token.  From my past experience with twitter app on android, I believe that reusing the obtained access tokens should work in subsequent requests.

 

When I try to do so, it gives me following error:

 

Fatal error: Uncaught Invalid username (401) 1-23 thrown in C:\wamp\www\ning\NingException.php on line 56

 

Do you have any idea about this error?

 

Thanks.

Mahendra.

 


I wrote some PHP code to upload a file to my Ning network.

 

However, the file get uploaded to my PHP server but when the code for uploading the image to my ning network gets executed, I get the following error:

 

Fatal error: Uncaught Bad photo. (400) 5-10 thrown in C:\wamp\www\ning\NingException.php on line 56

 

Do you have any idea what could be wrong? How can I solve this error?

 

Thanks in advance.

I believe you are using the Ning API PHP library. If so, make sure that you being the path to your file with an @. This tells PHP to include the contents of the specified file. Without it, the PHP code will try to upload a string that contains the path to file instead of the file itself. Checkout the adding a photo with the Ning API PHP library for an example.

Hello Devin,

 

I tried the example given in the documentation for uploading file using Ning API using PHP.

 

Yes, earlier I was not using the "@" sign and was getting this "Bad Photo" error. However, after including the "@" symbol, now I am landing into a new error which says "Curl cannot create form data".

 

Do you have any idea where am I making a mistake?

 

Thanks.

Here is the code which I use:

 

if (file_exists("upload/" . $_FILES["file"]["name"]))
            {
                echo $_FILES["file"]["name"] . " already exists. ";
            }
            else
            {
                move_uploaded_file($_FILES["file"]["tmp_name"],
                "upload/" . $_FILES["file"]["name"]);
                echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
                echo "Full path of the image: " .realpath('./upload/')  .'\\' .$_FILES["file"]["name"];
                $imagePath =  realpath('upload/')  .'/' .$_FILES["file"]["name"];
                echo " Imagepath is : " .$imagePath;
               
                // Ning Code
                // --------------
               
                require_once('NingApi.php');
                $subdomain = "myningdomain";
                $consumer_key = "my_key";
                $consumer_secret = "my_secret";
                $access_token = "";
                $access_token_secret = "";
               
                $ningApi = new NingApi($subdomain, $consumer_key, $consumer_secret);
                $email = $_REQUEST["emailaddress"];
                $password = $_REQUEST["password"] ;
               
                $loginMessage = "";
                try
                {
                    $result = $ningApi->login($email, $password);
                    $loginMessage = "success";
                }
                catch(Exception $e)
                {
                    $loginMessage = $e.getMessage();
                }
               

                $parts = array(
                    "title" => "My test photo",
                    "description" => "This is a test photo",
                    "file" => $imagePath
                );
               
                // Create a new photo
                $result = NingApi::instance()->photo->create($parts);
               
                print_r($result);
               
                print "Ning upload complete";
               
            }

 

----------------------------------

The exact error is :

 

Fatal error: Uncaught cURL error: failed creating formpost data thrown in "myfile_name" at line 208.

 

Can you help me with this error?

 

Thanks in advance.

Generally that error means that cURL can't find the file at the location you have specified. Check that the full path to the image is an absolute path and it's a valid location.

Hey guys im also trying to retrieve photos for a specific user

And honestly Im struggling... being a new Ning user and all ...(sigh)

 

I'd appreciate if possible from you guys, a php code snippet.

I read the information in the links that devin provided but i fail to translate it to php code.

 

Thanks in advance....

But which time is my local computer off by ? In comparison to the server time? OR whose time? I tried increasing my local clock but no different. I still get the error 
Error: The oauth_timestamp value is unacceptable to the Service Provider. The timestamp of the request must be within 300 seconds of the current time Acceptable range: 1322072573-1322073174

I'm using the wordpress plugin....

 

Thanks 


Devin said:

This error is generally caused when your local computer's time is more than five minutes off. I believe Windows has an option to update the time via the Internet. Try that option or try manually updating it.

The server disregards any old requests and uses the oauth_timestamp parameter to determine it.

Reply to Discussion

RSS

Blog Posts

Getting Started

Posted by Kyle Ford on October 13, 2010 at 8:00am 3 Comments

A Note on API Pricing

Posted by Phil McCluskey on October 1, 2010 at 8:55am 0 Comments

Welcome to Build!

Posted by Kyle Ford on September 30, 2010 at 8:30pm 1 Comment

Ning Status

© 2024   Created by Build Team.   Powered by

Badges  |  Report an Issue  |  Terms of Service