BrightcoveOS / php-wrapper-dynamic-ingest

A PHP wrapper for the Brightcove Dynamic Ingest API
MIT License
2 stars 4 forks source link

AWS Abstract Client error #3

Open hellomrdavis opened 7 years ago

hellomrdavis commented 7 years ago

Slowly but surely we're getting there but no matter what I've tried (several configurations from examples listed on the README page to the sample file provided) I constantly get this error:

` Notice: Trying to get property of non-object in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 361

Notice: Trying to get property of non-object in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 226

Warning: Attempt to assign property of non-object in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 239

Notice: Trying to get property of non-object in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 529

Notice: Trying to get property of non-object in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 530

Notice: Trying to get property of non-object in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 531

Fatal error: Uncaught TypeError: Argument 1 passed to Aws\Common\Client\AbstractClient::construct() must be an instance of Aws\Common\Credentials\CredentialsInterface, array given, called in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 531 and defined in /var/www/html/wp-content/plugins/amazon-web-services/vendor/aws/Aws/Common/Client/AbstractClient.php:73 Stack trace: #0 /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php(531): Aws\Common\Client\AbstractClient->construct(Array) #1 /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php(374): BCDIAPI->putFileToS3(Object(stdClass)) #2 /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php(251): BCDIAPI->make_request('put_files', Object(stdClass)) #3 /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php(176): BCDIAPI->process_files(Object(stdClass), Object(stdClass)) #4 /var/www/html/wp-content/plugins/ndms-video/ndms-video.php(402): BCDIAPI->ingest_request(Object(stdClass)) #5 /var/www/html/wp-includes/class-wp-ho in /var/www/html/wp-content/plugins/amazon-web-services/vendor/aws/Aws/Common/Client/AbstractClient.php on line 73`

I've checked and my account variables are being passed but it stops at this point. From what I've read I've come across a similar error from someone else plus a proposed solution: http://stackoverflow.com/questions/33594052/s3-client-initialization-error-via-php-sdk

hellomrdavis commented 7 years ago

Actually got it to work a few times and then this:

`Error:InvalidArgumentException: Credentials must be an instance of Aws\Credentials\CredentialsInterface, an associative array that contains "key", "secret", and an optional "token" key-value pairs, a credentials provider function, or false. in /var/www/html/wp-content/plugins/ndms-video/dist/vendor/Aws/ClientResolver.php:390 Stack trace:

0 /var/www/html/wp-content/plugins/ndms-video/dist/vendor/Aws/ClientResolver.php(267): Aws\ClientResolver::_apply_credentials(Array, Array, Object(Aws\HandlerList))

1 /var/www/html/wp-content/plugins/ndms-video/dist/vendor/Aws/AwsClient.php(151): Aws\ClientResolver->resolve(Array, Object(Aws\HandlerList))

2 /var/www/html/wp-content/plugins/ndms-video/dist/vendor/Aws/S3/S3Client.php(214): Aws\AwsClient->__construct(Array)

3 /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php(531): Aws\S3\S3Client->__construct(Array)

4 /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php(373): BCDIAPI->putFileToS3(Object(stdClass))

5 /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php(250): BCDIAPI->make_request('put_files', Object(stdClass))

6 /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php(193): BCDIAPI->process_files(Object(stdClass), Object(stdClass))

7 /var/www/html/wp-content/plugins/ndms-video/ndms-video.php(421): BCDIAPI->ingest_request(Object(stdClass))

8 /var/www/html/wp-includes/class-wp-hook.php(298): save_ndms_videos_meta(2926, Object(WP_Post), true)

9 /var/www/html/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('', Array)

10 /var/www/html/wp-includes/plugin.php(453): WP_Hook->do_action(Array)

11 /var/www/html/wp-includes/post.php(3494): do_action('save_postndms...', 2926, Object(WP_Post), true)

12 /var/www/html/wp-includes/post.php(3578): wp_insert_post(Array, false)

13 /var/www/html/wp-admin/includes/post.php(378): wp_update_post(Array)

14 /var/www/html/wp-admin/post.php(193): edit_post()

15 {main}`

Here is the function I created for when a post is saved and it calls the necessary functions, most taken from the sample file: `$options = get_option('plugin_options'); $videoToken = $options['video_feed_token']; $videoTag = $options['video_tag']; $playerPageSize = $options['video_page_size']; $videoURL = $options['video_url']; $playerID = $options['player_id'];

$postTitle = get_the_title();

if(isset($_FILES["ndms-video"])){ //$videoFile = get_post_meta( $post->ID, 'ndms-video', true ); $videoDownload = ndms_process_video($post_id, $postTitle); $videoURL = wp_get_attachment_url($videoDownload); // $videoURL = parse_url( wp_get_attachment_url($videoDownload) ); // $vurl = dirname( $videoURL [ 'path' ] ) . '/' . rawurlencode( basename( $videoURL[ 'path' ] ) ); }else{ $videoURL = null; }

// $poster_uploaded_url = ""; // $thumbnail_uploaded_url = ""; // update_post_meta( $post_id, 'ndms-tags', $_POST['ndms-tags'] );

if(isset($_POST["ndms-short-desc"])){ update_post_meta( $post_id, 'ndms-short-desc', $_POST["ndms-short-desc"] ); $videoShortDesc = iconv('ISO-8859-1','UTF-8', $_POST['ndms-short-desc']); }else{ $videoShortDesc = null; }

if(isset($_POST["ndms-long-desc"])){ update_post_meta( $post_id, 'ndms-long-desc', $_POST["ndms-long-desc"] ); $videoLongDesc = iconv('ISO-8859-1','UTF-8', $_POST['ndms-long-desc']); }else{ $videoLongDesc = null; }

if($_FILES['ndms-thumbnail']['name'] == ''){ $thumbnail_uploaded_url = get_post_meta( $post->ID, 'ndms-thumbnail', true ); }else{ $videoThumbnail = get_post_meta( $post->ID, 'ndms-thumbnail', true ); $thumbnail_uploaded_var = ndms_update_image($post_id,'thumbnail',$postTitle); // $thumbnail_uploaded_url = parse_url( wp_get_attachment_url($thumbnail_uploaded_var) ); $thumbnail_uploaded_url = wp_get_attachment_url($thumbnail_uploaded_var); // $thumbUrl = dirname( $thumbnail_uploaded_url[ 'path' ] ) . '/' . rawurlencode( basename( $thumbnail_uploaded_url[ 'path' ] ) ); }

if($_FILES['ndms-poster']['name'] == ''){ $poster_uploaded_url = get_post_meta( $post->ID, 'ndms-poster', true ); }else{ $posterUrl = null; $videoPoster = get_post_meta( $post->ID, 'ndms-poster', true ); $poster_uploaded_var = ndms_update_image($post_id,'poster',$postTitle); // $poster_uploaded_url = parse_url( wp_get_attachment_url($poster_uploaded_var) ); $poster_uploaded_url = wp_get_attachment_url($poster_uploaded_var); // $posterUrl = dirname( $poster_uploaded_url[ 'path' ] ) . '/' . rawurlencode( basename( $poster_uploaded_url[ 'path' ] ) ); }

/**

rcrooks commented 7 years ago

hmmm...I'll have to tinker with this one. Makes no sense to me that it would work several times, then stop. I found the AWS SDK pretty finicky to work with, but once I got it, it seemed to work consistently.

hellomrdavis commented 7 years ago

@rcrooks It's definitely been interesting. I found that if I use this in the plugin I'm writing, if I have the AWS Wordpress plugin installed(which is only V2 currently) it overrides the plugin I'm writing with V3 (using your wrapper). Weird. Any help on the above issue would be greatly appreciated.

rcrooks commented 7 years ago

@hellomrdavis the wrapper is definitely passing what AWS expects as credentials (this is around line 525 of bc-diapi.php), so ordinarily I would guess that the request for the S3 information (http://docs.brightcove.com/en/video-cloud/di-api/guides/push-based-ingest.html#S3urlRequest) is failing somehow - except that you said this worked a few times and then stopped working -- that's the real puzzler. What are you getting the $responses object that the wrapper returns when you send the request? Anything?

hellomrdavis commented 7 years ago

The $responses object is coming back empty. It was definitely weird that it worked perfectly for a moment but then it started popping up errors. If you'd like I could send you a ZIP file of my plugin so you can see the complete codebase. It's attached.

ndms-video.zip

rcrooks commented 7 years ago

I'll take a look at the code. It appears none of the requests being sent to wrapper are succeeding, so there must be something....

hellomrdavis commented 7 years ago

Great thanks. Look forward to seeing what you find.

rcrooks commented 7 years ago

@hellomrdavis just really started digging (nice app btw!) and doubt if this is the main issue, but in noms-video.php lines 370-374 I think you have the cases switched -- if $videoURL == null wouldn't you not want to include the videoURL in file_paths?

hellomrdavis commented 7 years ago

Something I've found. It's actually saving to Brightcove but nothing is being passed (video, poster, thumbnail, short description, etc.)

screen shot 2017-01-17 at 1 26 21 pm

rcrooks commented 7 years ago

It's actually encouraging to see something is working! Have a feeling this will turn out to be something in the data you're passing, or the way you're passing it.

hellomrdavis commented 7 years ago

I'm feeling that will be the case as well. I actually found the switched cases as well and fixed that. Still didn't fix the issue but it was a good catch.

hellomrdavis commented 7 years ago

So I've rewritten some things but still coming up with that same issue. If it helps here's the stack trace that's generated:

Error:InvalidArgumentException: Credentials must be an instance of Aws\Credentials\CredentialsInterface, an associative array that contains "key", "secret", and an optional "token" key-value pairs, a credentials provider function, or false. in /var/www/html/wp-content/plugins/ndms-video/dist/vendor/Aws/ClientResolver.php:390 Stack trace:

0 /var/www/html/wp-content/plugins/ndms-video/dist/vendor/Aws/ClientResolver.php(267): Aws\ClientResolver::_apply_credentials(Array, Array, Object(Aws\HandlerList))

1 /var/www/html/wp-content/plugins/ndms-video/dist/vendor/Aws/AwsClient.php(151): Aws\ClientResolver->resolve(Array, Object(Aws\HandlerList))

2 /var/www/html/wp-content/plugins/ndms-video/dist/vendor/Aws/S3/S3Client.php(214): Aws\AwsClient->__construct(Array)

3 /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php(531): Aws\S3\S3Client->__construct(Array)

4 /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php(373): BCDIAPI->putFileToS3(Object(stdClass))

5 /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php(250): BCDIAPI->make_request('put_files', Object(stdClass))

6 /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php(193): BCDIAPI->process_files(Object(stdClass), Object(stdClass))

7 /var/www/html/wp-content/plugins/ndms-video/ndms-video.php(520): BCDIAPI->ingest_request(Object(stdClass))

8 /var/www/html/wp-includes/class-wp-hook.php(298): save_ndms_videos_meta(3029, Object(WP_Post), true)

9 /var/www/html/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('', Array)

10 /var/www/html/wp-includes/plugin.php(453): WP_Hook->do_action(Array)

11 /var/www/html/wp-includes/post.php(3494): do_action('save_postndms...', 3029, Object(WP_Post), true)

12 /var/www/html/wp-includes/post.php(3578): wp_insert_post(Array, false)

13 /var/www/html/wp-admin/includes/post.php(378): wp_update_post(Array)

14 /var/www/html/wp-admin/post.php(193): edit_post()

15 {main}

And...

Notice: Trying to get property of non-object in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 225

Warning: Attempt to assign property of non-object in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 233

Notice: Trying to get property of non-object in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 529

Notice: Trying to get property of non-object in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 530

Notice: Trying to get property of non-object in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 531

And here is the final files path being passed in case you see any errors here: {"video": "/wp-content/uploads/2017/01/Screen-Shot-2017-01-05-at-10.49.30-AM.png","poster": "/wp-content/uploads/2017/01/usa-today-9782284.0-300x200.jpeg","thumbnail": "/wp-content/uploads/2017/01/small-1.mp4"}

hellomrdavis commented 7 years ago

So it's fixed once I comment out the "text tracks" snippet. Not sure why that was throwing off the script. Either way we're good to go. However I do have one off topic question. Is it possible to just update metadata through this wrapper? I'm getting the following error if I try to just change metadata and not pass any files: Notice: Trying to get property of non-object in /var/www/html/wp-content/plugins/ndms-video/dist/bc-diapi.php on line 385

rcrooks commented 7 years ago

Hi @hellomrdavis no, it's not possible to just update metadata through this one -- am planning to either add that or create a separate wrapper for pure CMS API operations -- leaning toward the latter, as there are a ton of endpoints for that one. Welcome your input on that though.

rcrooks commented 7 years ago

Also, can you tell me what exactly you commented out? Was that in your code or mine? If it was mine, I'd like to track down the issue and fix it.

hellomrdavis commented 7 years ago

Yeah it was from your code provided on the README for pushing source video: $text_tracks = '[{"path": "../assets/sample.vtt", "srclang": "en","kind": "captions","label": "EN","default": true}]';

As far as the metadata I would hate to have to include an additional wrapper purely for passing to the CMS API. Possible to maybe add a switch to the bc-diapi.php file that detects the metadata being passed along with a video ID. Once both are detected it fires a call to the CMS API? Not sure how complex the CMS API is though because you said there are a ton of endpoints.

rcrooks commented 7 years ago

Thanks for all that!

hellomrdavis commented 7 years ago

No problem. On another note, how intensive would it be to change this wrapper to work with AWS SDK version 2? I'm running into some issues with conflicting SDKs.

rcrooks commented 7 years ago

Not sure -- I haven't looked at version 2 at all -- I'll put that on the todo list

hellomrdavis commented 7 years ago

@rcrooks Been a while but I've run into an issue that really requires a dynamic ingest wrapper written for v2. Couple questions: 1) do you have a ballpark on how long it would take to do it and 2) how much would you charge to do it?