All docs This doc
Skip to end of metadata
Go to start of metadata

The Flickr connector allows you to connect to Flickr, which is an online photo management and sharing application. The connector uses the Flickr REST API to connect to Flickr and work with photos, people and more. ESB Templates and call mediator are used to send the requests to the Flickr REST endpoints. Underlying java classes help with the OAuth and signing process.

The following sections describe how to perform various operations with the connector. For general information on using connectors and their operations in your ESB configurations, see Using a Connector. To download the connector, go to https://store.wso2.com/store/assets/esbconnector/flickr, and click Download Connector. Then you can add and enable the connector in your ESB instance.


Connecting to Flickr

To use the Flickr connector, add the <flickr.init> element in your configuration before any other Flickr operations. This will keep the the information such as the API key, access token, and secrets to be used in the subsequent flickr operations.

init
<flickr.init>
   	<consumerKey>00a49886c96cd978d1c513cb2d33742b</consumerKey>
 	<consumerKeySecret>f20cca596738e959</consumerKeySecret>
	<accessToken>72157642842074863-5faf0186518885ab</accessToken>
  	<accessTokenSecret>70cd37fb502cb6fd</accessTokenSecret>
</flickr.init>
Entering secure data

For security purposes, you should store your SID and token in the WSO2 secure vault and reference it by an alias instead of hard-coding the actual values in the configuration file. For more information, see Working with Passwords.

Re-using Flickr configurations

For best results, save the Flickr configuration as a local entry. You can then easily reference it with the configKey attribute in your Flickr operations. For example, if you saved the above <flickr.init> entry as a local entry named MyFlickrConfig, you could reference it from an operation like getInfo as follows:

getInfo
<flickr.getInfo configKey="MyFlickrConfig">
	<userId>121275475@N06</userId>
	<format>json</format>
</flickr.getInfo>

Working with people

The following operations are available for working with people:

OperationDescription
getInfoGets the information about a user.
getPhotosReturns photos from the given user's photostream. Only photos visible to the calling user will be returned.

Getting information of a user 

getInfo
<flickr.getInfo>
	<userId>121275475@N06</userId>
</flickr.getInfo>

This will return the information about the user . Use this operation with the following properties.

Properties
  • userId: The ID of the user whose information needs to be retrieved.
Related Flickr documentation

https://www.flickr.com/services/api/flickr.people.getPhotos.html

Getting a list of photos belonging to a user 

getPhotos
<flickr.getPhotos>
	<userId>121275475@N06</userId>
	<minUploadDate>1356998400</minUploadDate>
	<maxUploadDate>1420070400</maxUploadDate>
	<minTakenDate>1356998400</minTakenDate>
	<maxTakenDate>1420070400</maxTakenDate>
	<extras>license</extras>
</flickr.getPhotos>

This operation will get the list of photos that belongs to the specified user . Following parameters can be used with the operation. Note that userId is the only mandatory parameter.

Properties
  • userId: The ID of the user whose photos needs to be retrieved.
  • minUploadDate: The minimum upload date. This is an optional parameter. Photos which were uploaded later or on the same date will be returned. The date should be in the form of a unix timestamp.
  • maxUploadDate : The maximum upload date. This is an optional parameter. Photos which were uploaded earlier or on the same date will be returned. The date should be in the form of a unix timestamp.
  • minTakenDate: The minimum taken date. This is an optional parameter. Photos which were taken later or on the same date will be returned. The date should be in the form of a mysql datetime.

  • maxTakenDate: The maximum taken date. This is an optional parameter. Photos which were taken earlier or on the same date will be returned. The date should be in the form of a mysql datetime.
  • extras: A comma-delimited list of extra information to fetch for each returned record. This is an optional parameter. Currently supported fields are:  description license , date_upload date_taken owner_name icon_server original_format last_update geo tags machine_tags o_dims views , media path_alias url_sq url_t url_s url_q url_m url_n url_z url_c url_l url_o
Related Flickr documentation

https://www.flickr.com/services/api/flickr.people.getPhotos.html


Working with photos

The following operations are available for working with photos:

OperationDescription
getPhotoInfoGets the information about a photo.The calling user should have permission to view the photo.
getExifRetrieves a list of EXIF/TIFF/GPS tags for a given photo. The calling user should have permission to view the photo.
addTagsAdds tags to a photo.
removeTagRemoves a tag from a photo.
deletePhotoDeletes a photo from flickr.

Getting information of a photo 

getPhotoInfo
<flickr.getPhotoInfo>
	<photoId>13376045033</photoId>
</flickr.getPhotoInfo>

This will return the information about the photo. Use this operation with the following properties.

Properties
  • photoId: The ID of the photo to retrieve information.
Related Flickr documentation

https://www.flickr.com/services/api/flickr.photos.getInfo.html

Getting a list of EXIF/TIFF/GPS tags for a given photo 

getExif
<flickr.getExif>
	<photoId>13376045033</photoId>
</flickr.getExif>

This operation retrieves a list of EXIF/TIFF/GPS tags for a given photo. The calling user must have permission to view the photo .

Properties
  • photoId: The ID of the photo for which EXIF data should be retrieved.
Related Flickr documentation

https://www.flickr.com/services/api/flickr.photos.getExif.html

Adding tags to a photo 

addTags
<flickr.addTags>
	<photoId>13376045033</photoId>
	<tags>wso2,stairs</tags>
</flickr.addTags>

This method will add tags to a given photo. When adding multiple tags, they should be separated by commas.

Properties
  • photoId: The ID of the photo to which tags should be added.
  • tags: The tags to be added to the photo.
Related Flickr documentation

https://www.flickr.com/services/api/flickr.photos.addTags.html

Removing a tag from a given photo 

removeTag
<flickr.removeTag>
	<tagId>121230153-13376045033-13969</tagId>
</flickr.removeTag>

This operation removes a tag from a photo.

Properties
  • tagId: The ID of the tag to be removed.
Related Flickr documentation

https://www.flickr.com/services/api/flickr.photos.getExif.html

Deleting a photo from Flickr 

deletePhoto
<flickr.deletePhoto>
	<photoId>13376045034</photoId>
</flickr.deletePhoto>

This operation deletes the specified photo from Flickr. The API key retrieved from Flickr should have the delete permission.

Properties
  • photoId: The ID of the photo to be deleted.
Related Flickr documentation

https://www.flickr.com/services/api/flickr.photos.delete.html


Working with comments

The following operations are available for working with comments:

OperationDescription
getCommentListReturns the comments for a photo.
addCommentAdds comment to a photo as the currently authenticated user.
editCommentEdits the text of a comment as the currently authenticated user.
deleteCommentDeletes a comment as the currently authenticated user.
getRecentCommentsForContactsReturn the list of photos belonging to your contacts that have been commented on recently.

Getting comments of a photo 

getCommentList
<flickr.getCommentList>
	<photoId>13376045033</photoId>
	<minDate>1356998400</minDate>
  	<maxDate>1420070400</maxDate>
</flickr.getCommentList>

This will return the list of comments of a given photo.

Properties
  • photoId: The ID of the photo for which the comments list should be retrieved.
  • minDate: The earliest date when a comment was added. This is an optional parameter. The date should be in the form of a unix timestamp.
  • maxDate: The latest date when a comment was added. This is an optional parameter. The date should be in the form of a unix timestamp.
Related Flickr documentation

https://www.flickr.com/services/api/flickr.photos.comments.getList.html

Adding a comment to a given photo 

addComment
<flickr.addComment>
	<photoId>13376045033</photoId>
	<comment>This is Awesome</comment>
</flickr.addComment>

This operation adds a comment to a specific photo. The calling user must have permission to view the photo.

Properties
  • photoId: The ID of the photo to which a comment should be added.
  • comment: comment text.
Related Flickr documentation

https://www.flickr.com/services/api/flickr.photos.comments.addComment.html

Editing a comment of a photo 

editComment
<flickr.editComment>
	<commentId>13376045033</commentId>
	<comment>This is Awesome</comment>
</flickr.editComment>

This method will edit the comment related to the relevant comment ID.

Properties
  • commentId: The ID of the comment to be edited.
  • comment: The comment text.
Related Flickr documentation

https://www.flickr.com/services/api/flickr.photos.comments.editComment.html

Deleting a comment from a photo 

deleteComment
<flickr.deleteComment>
	<commentId>13376045033</commentId>
</flickr.deleteComment>

This operation deletes a comment from a photo.

Properties
  • commentId: The ID of the comment to be deleted.
Related Flickr documentation

https://www.flickr.com/services/api/flickr.photos.comments.deleteComment.html

Getting the recently commented photos of contacts 

getRecentCommentsForContacts
<flickr.getRecentCommentsForContacts/>

This operation retrieves a list photos belonging to the calling user's contacts that have been commented on recently. This operation does not require any parameters.

Related Flickr documentation

https://www.flickr.com/services/api/flickr.photos.comments.getRecentForContacts.html


Testing Flickr API

The following operations are available to test the Flickr API:

OperationDescription
echoA testing method which echos a given value.
isLoggedA testing method which checks if the caller is logged in, and then returns their username.

Echo all parameters 

echo
<flickr.echo>
	<value>EchoValue</value>
</flickr.echo>

This will return the parameters and the echo value.

Properties
  • value: echo value.
Related Flickr documentation

https://www.flickr.com/services/api/flickr.test.echo.html

Check if the caller is logged 

isLogged
<flickr.isLogged/>

This operation will check if the calling user is logged  and then return the username. This operation does not require any parameters.

Related Flickr documentation

https://www.flickr.com/services/api/flickr.test.login.html


Response formats

Flickr API can send the response in many different formats. The default response format of the REST API is REST. However, you can add the parameter format to the request to change the response format. Possible values for the format parameter are as follows. See Flickr API docs for further details.

ValueDescription
restREST is the simplest response format to use - it's a simple XML block.
xmlrpcTo return the response in XML-RPC format, include a parameter for format in the request with xmlrpc as the value.
soap  To return the response in SOAP format, include a parameter for format in the request with soap as the value.
jsonTo return an API response in JSON format, include a parameter for format in the request with json as the value.

Changing the response format 

response
<flickr.getPhotoInfo>
	<photoId>13376045033</photoId>
	<format>json</format>
</flickr.getPhotoInfo>

Please read the json object representation format used by the Flickr API before working with the json responses.

 


Example

Following example shows how to make use of the Flickr connector.

Proxy Configuration
<proxy xmlns="http://ws.apache.org/ns/synapse">
       name="flickr_connector_test"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
    <target>
        <inSequence>
            <property name="consumerKey" expression="json-eval($.json_payload.consumerKey)"/>
            <property name="consumerKeySecret" expression="json-eval($.json_payload.consumerKeySecret)"/>
            <property name="accessToken" expression="json-eval($.json_payload.accessToken)"/>
            <property name="accessTokenSecret" expression="json-eval($.json_payload.accessTokenSecret)"/>
            <property name="photoId" expression="json-eval($.json_payload.photoId)"/>
            <property name="comment" expression="json-eval($.json_payload.comment)"/>
			<property name="tags" expression="json-eval($.json_payload.tag)"/>
            <flickr.init>
                <consumerKey>{$ctx:consumerKey}</consumerKey>
                <consumerKeySecret>{$ctx:consumerKeySecret}</consumerKeySecret>
                <accessToken>{$ctx:accessToken}</accessToken>
                <accessTokenSecret>{$ctx:accessTokenSecret}</accessTokenSecret>
            </flickr.init>
            <flickr.addComment>
                <photoId>{$ctx:photoId}</photoId>
                <comment>{$ctx:comment}</comment>
            </flickr.addComment>
			<flickr.addTags>
                <photoId>{$ctx:photoId}</photoId>
                <tags>{$ctx:tags}</tags>
            </flickr.addTags>
        </inSequence>
        <outSequence>
            <send/>
        </outSequence>
    </target>
</proxy>

When invoked with the request below, above proxy will add a comment and a tag to the specified photo.

Request
{"json_payload":
    {
    "photoId":"13376045033",
    "comment":"Flickr connector is Awesome!",
    "tag":"wso2",
    "consumerKey":"00a49886c96cd978d1c513cb2d33742b",
    "consumerKeySecret":"f20cca596738e959",
    "accessToken":"72157642842074863-5faf0186518885ab",
    "accessTokenSecret":"70cd37fb502cb6fd"
    }
}
  • No labels