i been trying to add subtitles to videos subtitle file is uploading and got medaid and then i called media/subtitles/create endpoint with params
{
"media_id":"692797692624265216",
"media_category":"TweetVideo",
"subtitle_info": {
"subtitles": [
"media_id":"105195515189863968",
"language_code":"EN", //The language code should be a BCP47 code (e.g. 'en", "sp"),
"display_name":"English"
]
}
}
but its returning undefined index media_type then i passed media_type then it returned undefined index media, that also i passed then i got undefined media_string_id after passing that value i got Undefined property: stdClass::$media_id_string’, in document these values are not specified for subtitle creation
any thought on these please share your thoughts
ok i fixed this issue with below codes
$media_type = mime_content_type($local_file_path);
$subtitleMediaDetails = $connection->upload('media/upload', ['media' =>$local_file_path, 'media_type' =>$media_type, 'media_category'=> 'Subtitles'],true);
$subtitleMedaiId = $subtitleMediaDetails->media_id;
if($subtitleMedaiId) {
$json = '{
"media_id":"'.$media->media_id.'", // uploaded video id
"media_category":"TweetVideo",
"subtitle_info": {
"subtitles": [
{
"media_id":"'.$subtitleMedaiId.'", //uploaded subtitle video id
"language_code":"EN",
"display_name":"English"
}
]
}
}';
$metadata_payload = json_decode($json, true);
$connection->setTimeouts(60, 60);
$createdSubritleResponse = $connection->post('media/subtitles/create', $metadata_payload, true);
}
Related
When I make a request to my webservice one time I get:
funcion login returns => {
"token":"fsuehfisubfibiefasasdapmwineq","client":"Admin","permission":"ADMIN"
}
And I can just save something like the client or the token in a variable, doing for example:
$json = login($email,$password); - saving the JSON in the variable $json.
$values = json_decode($json); - decoding the $json and saving it on $values.
And know if I want to save the name or the token for future requests to the webservice I make a variable:
$token = $values->{'token'};
$client = $values->{'client'};
But my question is what i do when i get this from the webservice, because I did the same and tried somethings and I'm not getting anywhere.
funcion member returns = {
"Table":[
{
"client":"Admin",
"name":"Martin Lupin",
"age":"25",
"city":"Lisbon"
}
]
}
How do I access to "client", "name", "age", "city"?
I tried to do:
$name = $valuesclient->{'client'}; - and nothing
$name = $valuesclient->{'table'}->{'client'}; - and nothing
$name = $valuesclient->{'table'->{'client'}}; - and nothing
Can someone help me?
I am using jwilsson's spotify-web-api-php to return data from the Spotify API using PHP.
Also I'm using digitalnature's php-ref to return info about variables.
This is my code, apologies for the fact it's probably full of errors, misconceptions, rubbish etc.
// https://stackoverflow.com/questions/4345554/convert-a-php-object-to-an-associative-array
function objectToArray($r)
{
if (is_object($r)) {
if (method_exists($r, 'toArray')) {
return $r->toArray(); // returns result directly
} else {
$r = get_object_vars($r);
}
}
if (is_array($r)) {
$r = array_map(__FUNCTION__, $r); // recursive function call
}
return $r;
}
$session = new SpotifyWebAPI\Session(
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
);
$session->requestCredentialsToken();
$accessToken = $session->getAccessToken();
$api = new SpotifyWebAPI\SpotifyWebAPI();
$api->setAccessToken($accessToken);
$search = $api->search('fugazi','artist');
// convert object to array
$fff = objectToArray($search);
// php-ref to view info about the $fff array
r($fff);
// try to access the total value
$v1 = $fff[0]['artists']['total'];
This is what the php-ref looks like for the $fff variable:
I tried to access the total attribute via:
$v1 = $fff[0]['artists']['total'];
But receive these errors:
PHP Notice: Undefined offset: 0 in C:\websites\spotify\search.php on line 49
PHP Notice: Trying to access array offset on value of type null in C:\websites\spotify\search.php on line 49
PHP Notice: Trying to access array offset on value of type null in C:\websites\spotify\search.php on line 49
Sorry for asking a silly question and for not understanding what I'm doing, but, what am I doing wrong?
I have created a JSON file which I will use as a datasource for global configurations of the app.
Excerpt from json file
//Have not put the complete json file. No error in the file
{
"loginType":[
{
"name":"Facebook",
"url":"#",
"method":"",
"label":"Continue with Facebook",
"type":"social",
"class":"",
"icon":"",
"callBack_url" : "fbLoginUrl",
"providerButton":"<div class='fb-login-button' data-max-rows='1'
data-size='large' data-button-type='continue_with' data-use-
continue-as='true'></div>"
},
{
"name":"Twitter",
"url":"#",
"method":"logInWithTwitter()",
"label":"Continue with Twitter",
"type":"social",
"class":"",
"icon":"",
"callBack_url" : "twitterLoginUrl",
"providerButton" :""
}
]
}
The callBack_url key in the json file has a variable with a similar name which has a url as its value e.g $twitterLoginUrl = "https://some.site.com/twitter_login?param1"
$jsonData_signIn =json_decode
(file_get_contents(/path/to/oauth2_provider.json));
$oauth2Provider = jsonData_signIn->loginType;
foreach($oauth2Provider as $type){
if($type->type == 'local' ){
echo "{$type->label}";
}
}
For the above, as output for the link I get eg Continue with facebook
echo "{$type->label}";
The reason I am not storing the complete URI is I will generate some parameters dynamically.
Take a look at the manual for variable variables: http://php.net/manual/en/language.variables.variable.php
You basically just wrap the string variable name in ${ } to make it behave like an actual variable.
$fbLoginUrl = 'https://www.facebook.com/v2.10/dialog/oauth?client_id=xxxxxxx&state=xxxxxxx&response_type=code&sdk=php-sdk-5.6.2&redirect_uri=some.site.com/fbLogin.php&scope=public_profile';
$json = '{"callBack_url" : "fbLoginUrl"}';
$decoded = json_decode($json);
echo ${$decoded->callBack_url};
This is my JSON file which I get from an external link:
[
{
"Id":441,
"Name":"Gary"
},
{
"Id":1864,
"Name":"Bob"
}
]
When I try and display the Id and Name, I receive the error:
Notice: Trying to get property of non-object
$file = file_get_contents('http://linktojson.com');
$decode = json_decode($file, false);
$name = $decode->Name;
$id = $decode->Id;
echo $name;
echo $id;
Your json data has nested objects. So you need to access it like this:
$decode[0]->Name;
See here: https://3v4l.org/2aY22
Seeing as you have multiple objects with the same structure, you probably want to loop over them, like this:
foreach($decode AS $person) {
echo $person->Id . ": " . $person->Name;
}
Side note: it really helps to examine your data structure if you're having trouble navigating it. Just doing a var_dump($decode); shows you quite clearly how it is structured and how you need to access it!
this is my code
public function movieInfo($movieId = null) {
// get the data
$movie = $this->repository->load($movieId);
$this->set_title(null);
$data = $this->includes;
$content_data = array(
'movie' => $movie,
);
$data['content'] = $this->load->view('movie/movie_info', $content_data, true);
$this->load->view($this->template, $data);
}
when i browse to http://tmdb.instaplace.me/movie/movieinfo/76341 it shows my page
but when i browse to http://tmdb.instaplace.me/movie/movieinfo/0
it shows a uncaught exception page when error reporting is set to development otherwise it shows a blank page
instead of showing blank page or uncaught exception on development i want to show a page that says "The id does not exist" for example or a 404 page
but my problem is i can't figure it out how to do that, i am using this
php-tmdb wrapper
the $movieId variable is the id from themoviedb.org to find the movie based on the id
if( ! $movie = $this->repository->load($movieId) ){
$this->_showMovieNotFoundFor($movieId) ; }
else{ $this->_showFound($movie) ; }
edit in response to question ====
you have to create the _show methods yourself. the idea is that you are just checking if a movie came back from the database or not. in the controller the simpler you can make your methods the easier it is to maintain. and unless a method in a controller has to be public, always make them private. in codeigniter you can just put an underscore before the method name to make it private. so the code
if( ! $movie = $this->repository->load($movieId)
so if the $movie did NOT come back from database - then go to
$this->_showMovieNotFoundFor($movieId) ;
i included $movieId in case its needed for the error message.
otherwise you got $movie from database so go to
$this->_showFound($movie) ;
where if we just paste your code its going to be something like
function _showFound($movie){
$this->set_title(null);
$data = $this->includes;
$content_data = array(
'movie' => $movie,
);
$data['content'] = $this->load->view('movie/movie_info', $content_data, true);
$this->load->view($this->template, $data);
}