Open hellomrdavis opened 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:
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' ] ) ); }
/**
Push to Brightcove API */
// Create Brightcove API Access Token
// Include the BCDIAPI SDK require 'dist/bc-diapi.php';
// to ingest new video (upload source files) $video_metadata = '{"name":"'.$postTitle.'","description": "'.$videoShortDesc.'", "long_description" : "'.$videoLongDesc.'", "tags":["'.$videoTag.'"]}'; $push_ingest_data = '{"profile": "videocloud-default-v1","capture-images": false}'; if($videoURL == null && isset($_POST['ndms_video_true'])){ $file_paths = '{"video": "'.$videoURL.'","poster": "'.$poster_uploaded_url.'","thumbnail": "'.$thumbnail_uploaded_url.'"}'; }else{ $file_paths = '{"poster": "'.$poster_uploaded_url.'","thumbnail": "'.$thumbnail_uploaded_url.'"}'; }
// $file_paths = '{"poster": "'.$poster_uploaded_url.'","thumbnail": "'.$thumbnail_uploaded_url.'"}'; $text_tracks = '[{"srclang": "en","kind": "captions","label": "EN","default": true}]';
$push_options = new stdClass(); if(isset($_POST['ndms_video_true'])){ $push_options->video_id = $_POST['ndms_video_true']; } $push_options->video_options = $video_metadata; $push_options->ingest_options = $push_ingest_data; $push_options->file_paths = $file_paths; $push_options->text_tracks = $text_tracks;
$account_info = new stdClass();
$options = get_option('plugin_options'); $playerAccount = $options['player_account']; $bcClientId = $options['brightcove_client_id']; $bcClientSecret = $options['brightcove_client_secret'];
if (isset($playerAccount)) { $account_info->account_id = $playerAccount; } else { echo 'Account id is required!'; } if (isset($bcClientId)) { $account_info->client_id = $bcClientId; } else { echo 'Client id is required!'; } if (isset($bcClientSecret)) { $account_info->client_secret = $bcClientSecret; } else { echo 'Client secret is required!'; }
// account information $account_data = json_encode($account_info);
// Instantiate the class, passing it the account information.
$bcdi = new BCDIAPI($account_data);
// make a request // $responses = $bcdi->ingest_request($push_options);
try { // make request $responses = $bcdi->ingest_request($push_options); update_post_meta( $post_id, 'ndms-video-id', $responses->cms->id ); wp_delete_attachment( $videoDownload ); } catch(Exception $error) { // Handle our error echo "Error: " . $error;
die(); }`
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.
@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.
@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?
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.
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....
Great thanks. Look forward to seeing what you find.
@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?
Something I've found. It's actually saving to Brightcove but nothing is being passed (video, poster, thumbnail, short description, etc.)
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.
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.
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:
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"}
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
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.
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.
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.
Thanks for all that!
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.
Not sure -- I haven't looked at version 2 at all -- I'll put that on the todo list
@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?
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