danriegsecker / as3flickrlib

Automatically exported from code.google.com/p/as3flickrlib
0 stars 0 forks source link

Invalid Signature when trying to upload #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm trying to use it to upload images to Flickr, but I am getting an error
code of 96 or Invalid Signature. I suspect it's because AS3's FileReference
class includes two extra variables "Upload" and "Filename" which trace out
if I send it to a php script.

More information here: http://bcdef.org/?p=22

Original issue reported on code.google.com by darron.schall on 13 Dec 2006 at 9:35

GoogleCodeExporter commented 9 years ago

Original comment by darron.schall on 13 Dec 2006 at 9:36

GoogleCodeExporter commented 9 years ago
Possible fix from Owen van Dijk:

/**
         * Uploads a photo to the Flickr service
         *
         * @param fileReference The fileReference that the user "browsed" to
         *      so that upload works correctly.
         * @param title (Optional) The title of the photo.
         * @param description (Optional) A description of the photo. May contain
         *      some limited HTML.
         * @param tags (Optional) A space-seperated list of tags to apply to
         *      the photo.
         * @param is_public (Optional) True if the photo is public, false otherwise
         * @param is_friend (Optional) True if the photo should be marked for friends,
         *      false otherwise
         * @param is_family (Optional) True if the photo should be marked for family
         *      access only, false otherwise
         * @langversion ActionScript 3.0
         * @playerversion Flash 8.5
         * @tiptext
         */
        public function upload( fileReference:FileReference, 
                                title:String = "",
                                description:String = "",
                                tags:String = "",
                                is_public:Boolean = false,
                                is_friend:Boolean = false,
                                is_family:Boolean = false ) : void {
            // The upload method requires signing, so go through
            // the signature process

            // [OvD] Flash sends both the 'Filename' and the 'Upload' values
            // in the body of the POST request, so these are needed for the signature
            // as well, otherwise Flickr returns a error code 96 'invalid signature'
            var sig:String = StringUtil.trim( _service.secret );
            sig += "Filename" + fileReference.name;
            sig += "UploadSubmit Query"; //
            sig += "api_key" + StringUtil.trim( _service.api_key );
            sig += "auth_token" + StringUtil.trim( _service.token );

            // [OvD] optional values, the order is irrelevant
            if ( description != "" ) sig += "description" + description;
            if ( is_family ) sig += "is_family" + ( is_family ? 1 : 0 );
            if ( is_friend ) sig += "is_friend" + ( is_friend ? 1 : 0 );
            if ( is_public ) sig += "is_public" + ( is_public ? 1 : 0 );
            if ( tags != "" ) sig += "tags" + tags;
            if ( title != "" ) sig += "title" + title;

            var vars:URLVariables = new URLVariables();
            vars.auth_token = StringUtil.trim( _service.token );
            vars.api_sig = MD5.hash( sig );
            vars.api_key = StringUtil.trim(  _service.api_key );

            // [OvD] optional values, same order as the signature
            if ( description != "" ) vars.description = description;
            if ( is_family ) vars.is_family = ( is_family ? 1 : 0 );
            if ( is_friend ) vars.is_friend = ( is_friend ? 1 : 0 );
            if ( is_public ) vars.is_public = ( is_public ? 1 : 0 );
            if ( tags != "" ) vars.tags = tags;
            if ( title != "" ) vars.title = title;

            var request:URLRequest = new URLRequest( UPLOAD_DEST );
            request.data = vars;
            request.method = URLRequestMethod.POST;

            // [OvD] Flickr expects the filename parameter to be named 'photo'
            fileReference.upload( request, "photo" );
        }

Original comment by darron.schall on 16 Dec 2006 at 2:48

GoogleCodeExporter commented 9 years ago
I have 6 peopler report that the actual uploading works :)

Original comment by owen.van...@gmail.com on 22 Dec 2006 at 2:08

GoogleCodeExporter commented 9 years ago
Awesome owen, thanks for your help here.

Before I would consider upload complete, I'd like to implement an event 
listener for
"uploadCompleteData" so we can actually report the upload response from Flickr 
(the
new photo id).  A sample upload reponse is the following XML:  

<photoid>1234</photoid>

We'll probably want to have an UPLOAD_COMPLETE event in the AS3 API to report 
back
that information to the user.  For upload progress, they can add the appropriate
event listener to the fileReference object.

Original comment by darron.schall on 22 Dec 2006 at 2:12

GoogleCodeExporter commented 9 years ago
Cool, let me update when i have that code implemented. It needs some work from 
Adobe
first for this.

Original comment by owen.van...@gmail.com on 22 Dec 2006 at 2:29

GoogleCodeExporter commented 9 years ago
Yeah. Can we implement this in such a way that it works in 9.0 but you dont get
confirmation that it worked, but if you do it in the latest player, you get 
events
with the response, and confirmation?

Original comment by mikechambers on 22 Dec 2006 at 6:39

GoogleCodeExporter commented 9 years ago
As far as getting a response from Flickr - this would only be possible with 
Players
9,0,28,0+ because of the existance of the "uploadCompleteData" event.

In the case that you're using an older player, that "uploadCompleteData" event 
will
never fire, and there will never be a response for the photoId of the uploaded 
photo.
   We can add a listener for it in either case, but only in 9,0,28,0+ will the
listener be executed.

I don't think there's anything special we need to code for the behavior, I 
think the
default behavior does what you want... unless I'm misreading it?

The upload itself will work either way, but we can only get the photoid of the
uploaded photo in 9,0,28,0+.  In the older player case, the user will have to 
add a
"complete" handler to the fileReference to know when the upload is complete.  
In the
newer player case, they can lsiten for UPLOAD_COMPLETE from the AS3 Flickr API 
lib.

In all cases, upload progress events will be dispatched from the fileReference
itself, and not from the AS3 lickr API lib.

Original comment by darron.schall on 22 Dec 2006 at 7:22

GoogleCodeExporter commented 9 years ago
So, shall i implement the UPLOAD_COMPLETE event? I think it's not really 
necessary,
since as a developer you can do all the stuff you want from the fileReference.

Original comment by owen.van...@gmail.com on 10 Jan 2007 at 1:53

GoogleCodeExporter commented 9 years ago
I just checked in Owen's changes, and confirmed that upload is working in the 
current source (not in SWC 
yet).

See this post for more info:

http://groups.google.com/group/as3flickrlib/browse_thread/thread/a1a2fa0b6fb2afa
1/84e83e4c31fdbce6#
84e83e4c31fdbce6

We need to add some checks to make sure key, secret and token are set correctly.

Original comment by mikechambers on 20 Jun 2007 at 1:17

GoogleCodeExporter commented 9 years ago
Oops...totally missed this thread..my bad. I'll rewrite my patch, adding the 
vars
check like Mike suggested.

Original comment by owen.van...@gmail.com on 9 Jul 2007 at 12:48

GoogleCodeExporter commented 9 years ago
I have updated the Flickr upload code to include missing upload parameters, so 
this
should now work according to the Flickr API spec. Patch is attached.

Original comment by spjwebster@gmail.com on 2 Aug 2007 at 4:41

Attachments:

GoogleCodeExporter commented 9 years ago
Upload works fine...thanks

Original comment by nekoupo...@gmail.com on 22 Aug 2007 at 10:15

GoogleCodeExporter commented 9 years ago
Fixed upload API compatibility in revision 30 (r30). Marking as FIXED.

Original comment by spjwebster@gmail.com on 2 Feb 2008 at 4:08