Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS Abstract Client error #3

Open
hellomrdavis opened this issue Jan 12, 2017 · 20 comments
Open

AWS Abstract Client error #3

hellomrdavis opened this issue Jan 12, 2017 · 20 comments

Comments

@hellomrdavis
Copy link

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
Copy link
Author

hellomrdavis commented Jan 13, 2017

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_post_ndms_...', 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' ] ) );
}

/**

  • 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();

}`

@rcrooks
Copy link
Contributor

rcrooks commented Jan 13, 2017

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
Copy link
Author

@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
Copy link
Contributor

rcrooks commented Jan 14, 2017

@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
Copy link
Author

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
Copy link
Contributor

rcrooks commented Jan 17, 2017

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
Copy link
Author

Great thanks. Look forward to seeing what you find.

@rcrooks
Copy link
Contributor

rcrooks commented Jan 17, 2017

@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
Copy link
Author

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
Copy link
Contributor

rcrooks commented Jan 17, 2017

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
Copy link
Author

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
Copy link
Author

hellomrdavis commented Jan 19, 2017

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_post_ndms
...', 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
Copy link
Author

hellomrdavis commented Jan 19, 2017

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
Copy link
Contributor

rcrooks commented Jan 20, 2017

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
Copy link
Contributor

rcrooks commented Jan 20, 2017

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
Copy link
Author

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
Copy link
Contributor

rcrooks commented Jan 21, 2017

Thanks for all that!

@hellomrdavis
Copy link
Author

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
Copy link
Contributor

rcrooks commented Jan 24, 2017

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

@hellomrdavis
Copy link
Author

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants