Accessing the Ning API with cURL¶
cURL is a command line utility that can be used to interact with the Ning API. It is mostly used for playing around with the Ning API. In this example, all requests use the xn_pretty=true parameter to make responses easier to read.
All of the requests using the following consumer credentials:
- Consumer Key
- 0d716e57-5ada-4b29-a33c-2f4af1b26837
- Consumer Secret
- f0963fa5-1259-434f-86fc-8a17d14b16ca
The photo requests use the following token:
- Access Key
- a2f85402-f16c-4677-91e2-a334d362ad47
- Access Secret
- b42a0833-e1e2-4b02-a906-258a157bc702
Retrieving tokens¶
#!/bin/bash
# Request the access token for the given member using the Ning API
curl -u test@example.com \
-d 'oauth_signature_method=PLAINTEXT&oauth_consumer_key=0d716e57-5ada-4b29-a33c-2f4af1b26837&oauth_signature=f0963fa5-1259-434f-86fc-8a17d14b16ca%26' \
'https://external.ningapis.com/xn/rest/apiexample/1.0/Token?xn_pretty=true'
Response:
{
"success" : true,
"entry" : {
"author" : "2cpor74jnszaj",
"oauthConsumerKey" : "0d716e57-5ada-4b29-a33c-2f4af1b26837",
"oauthToken" : "f450a524-652b-4700-9877-b2e8868fc0ca",
"oauthTokenSecret" : "0cc82e2f-1a6b-4747-b846-01681ac5e25d"
},
"resources" : {
}
}
Retrieving photos¶
#!/bin/bash
# Query the Ning API for the five most recent photos, returning the photo's
# title and the URL of the image
curl -H 'Authorization: OAuth oauth_signature_method="PLAINTEXT",oauth_consumer_key="0d716e57-5ada-4b29-a33c-2f4af1b26837",oauth_token="a2f85402-f16c-4677-91e2-a334d362ad47",oauth_signature="f0963fa5-1259-434f-86fc-8a17d14b16ca%26b42a0833-e1e2-4b02-a906-258a157bc702"' \
'https://external.ningapis.com/xn/rest/apiexample/1.0/Photo/recent?xn_pretty=true&fields=title,image.url,title&count=5'
Response:
{
"success" : true,
"anchor" : "uxxWYGU-F4KrKZhlAq2toZ4o2xoGphLM",
"firstPage" : true,
"lastPage" : false,
"entry" : [ {
"id" : "3011345:Photo:3120",
"author" : "2cpor74jnszaj",
"createdDate" : "2010-09-29T20:21:27.120Z",
"title" : "Updated Photo Title",
"image" : "3011345:Photo:3120"
}, {
"id" : "3011345:Photo:3112",
"author" : "2cpor74jnszaj",
"createdDate" : "2010-09-29T20:07:16.112Z",
"title" : "Updated Photo Title",
"image" : "3011345:Photo:3112"
}, {
"id" : "3011345:Photo:3110",
"author" : "2cpor74jnszaj",
"createdDate" : "2010-09-29T20:06:36.110Z",
"title" : "Photo Title",
"image" : "3011345:Photo:3110"
}, {
"id" : "3011345:Photo:3108",
"author" : "2cpor74jnszaj",
"createdDate" : "2010-09-29T19:09:39.108Z",
"title" : "Expedition 24 Soyuz Landing (201009250033HQ)",
"image" : "3011345:Photo:3108"
}, {
"id" : "3011345:Photo:3105",
"author" : "2cpor74jnszaj",
"createdDate" : "2010-09-29T19:09:34.105Z",
"title" : "Here Comes Comet Hartley 2! (NASA, Comets, 09/28/10)",
"image" : "3011345:Photo:3105"
} ],
"resources" : {
"3011345:Photo:3120" : {
"url" : "http://dummy.dummy/ning-bitc-xno-files796485162.ico"
},
"3011345:Photo:3112" : {
"url" : "http://dummy.dummy/ning-bitc-xno-files947479844.ico"
},
"3011345:Photo:3110" : {
"url" : "http://dummy.dummy/ning-bitc-xno-files913925400.ico"
},
"3011345:Photo:3108" : {
"url" : "http://dummy.dummy/ning-bitc-xno-files658415210.ico"
},
"3011345:Photo:3105" : {
"url" : "http://dummy.dummy/ning-bitc-xno-files830038508.ico"
}
}
}
Add a new photo¶
#!/bin/bash
# Upload a photo using the Ning API
curl -H 'Authorization: OAuth oauth_signature_method="PLAINTEXT",oauth_consumer_key="0d716e57-5ada-4b29-a33c-2f4af1b26837",oauth_token="a2f85402-f16c-4677-91e2-a334d362ad47",oauth_signature="f0963fa5-1259-434f-86fc-8a17d14b16ca%26b42a0833-e1e2-4b02-a906-258a157bc702"' \
-F 'title=Photo Title' \
-F 'description=Photo Description' \
-F 'file=@/home/test/img/cat.jpg' \
'https://external.ningapis.com/xn/rest/apiexample/1.0/Photo?xn_pretty=true'
Response:
{
"success" : true,
"id" : "3011345:Photo:3120"
}
Update a photo¶
#!/bin/bash
# Update a photo using the Ning API
curl -X PUT \
-H 'Authorization: OAuth oauth_signature_method="PLAINTEXT",oauth_consumer_key="0d716e57-5ada-4b29-a33c-2f4af1b26837",oauth_token="a2f85402-f16c-4677-91e2-a334d362ad47",oauth_signature="f0963fa5-1259-434f-86fc-8a17d14b16ca%26b42a0833-e1e2-4b02-a906-258a157bc702"' \
-d 'id=3011345:Photo:3120' \
-d 'title=Updated Photo Title' \
-d 'description=Updated Photo Description' \
'https://external.ningapis.com/xn/rest/apiexample/1.0/Photo?xn_pretty=true'
Response:
{
"success" : true
}
Delete a photo¶
#!/bin/bash
# Delete a photo using the Ning API
curl -X DELETE \
-H 'Authorization: OAuth oauth_signature_method="PLAINTEXT",oauth_consumer_key="0d716e57-5ada-4b29-a33c-2f4af1b26837",oauth_token="a2f85402-f16c-4677-91e2-a334d362ad47",oauth_signature="f0963fa5-1259-434f-86fc-8a17d14b16ca%26b42a0833-e1e2-4b02-a906-258a157bc702"' \
'https://external.ningapis.com/xn/rest/apiexample/1.0/Photo?xn_pretty=true&id=3011345:Photo:3120'
Response:
{
"success" : true
}