How to Updating rowHeight table google slide api - php

I'm using Google Slide API to generate presentation, and I want to create table using this API, I try this function to do it and it worked well, but it create table with "rowHeight": { "magnitude": 3000000, "unit": "EMU" },
I want to modify this value, But I didn't found how.
The G-slide API has just this fields to insert new row :
'insertTableRows'=> array(
'tableObjectId'=> $tableId,
'cellLocation'=> array(
'rowIndex'=> $rowIndex
),
'insertBelow'=> $insertBelow,
'number'=> $number
)
When I use this function I got the problem above.

Related

WP Rest API Custom endpoint - JSON returns NULL

I am trying to slim down the JSON returned when using the Rest API. I am able to get it to work using the "_embed" parameter in the query, but it returns a HUGE amount of data I don't need. So, per WP best practices I want to set up a custom end point and in it's callback call a function to output the three items I need. Seems simple, however it returns NULL for all nodes when I try. In my functions.php file I have:
function get_all_posts( WP_REST_Request $request ) {
return [
'id' => $data->data['id'],
'title' => $data->data['title']['rendered'],
'link' => $data->data['link'],
'date' => $data->data['date'], //not correct
//similar calls to get thumbnail image and category
];
}
Then the route and call back for the custom endpoint
add_action( 'rest_api_init', function () {
register_rest_route( 'mydata/v1', '/all', array(
'methods' => 'GET',
'callback' => 'get_all_posts',
) );
} );
when I use the url - https://somedomain.com/blog/wp-json/mydata/v1/all I get the following on page:
{
"id": null,
"title": null,
"link": null
}
You can pass field arguments to the API
Like so:
[url]/wp-json/wp/v2/tags?fields=id,name
Note this is example is /tags, you can use /categories etc, and still specify the fields.
I recommend installing the JSONView chrome plugin so that the dump of your JSON is readable when you test the endpoint .

YouTube API v3 get last video in playlist

Some basic background: I help run a gaming channel on YouTube, and I'm building a utility (using PHP) to integrate the channel's content with a companion website. Our playlists are primarily "let's play" series ordered by publication date that follow chronological progress through various games, and I would like the website to display the "latest episode" from a select number of series.
I know that I can work my way to the last video by chaining calls to the following:
$youtubeService->playlistItems->listPlaylistItems(
"snippet",
array(
"playlistId" => $playlistId
"pageToken" => $nextPageToken
)
)
And simply grab the last item in the response set when $nextPageToken is unset.
However, this strikes me as incredibly inefficient--partly because I believe it eats away at my API request quota, but mostly because it's going to slow down the overall response time of the site. Neither of those are ideal.
It seems like there should be an easier way to grab the "latest" video in a playlist either by changing the order of the response, or with some handy function, but I can't find any documentation on it.
I've looked at using the Search functions over the PlaylistItems, but (according to the documentation), Search only accepts Channel IDs as a parameter and not Playlist IDs, which makes me think that its the wrong direction to head.
The short answer here is that this appears to be impossible under the current version of the API. There is no apparent way to essentially select videos in reverse, but I did make a minor change which resulted in whole process being a tad more efficient.
This is the original code:
$items = $youtube->playlistItems->listPlaylistItems(
"snippet",
array(
"playlistId" => $playlistId,
"maxResults" => 50
)
);
while ($items->nextPageToken) {
$items = $youtube->playlistItems->listPlaylistItems(
"snippet",
array(
"playlistId" => $playlistId,
"maxResults" => 50,
"pageToken" => $items->nextPageToken
)
);
}
if ($items) {
return end($items->getItems());
}
This is the fix:
First, I added an object to assist with caching:
class PlaylistCache {
protected $expirationDate;
protected $playlistId;
protected $latestEpisode;
__construct($playlistId, $latestEpisode) {
$this-playlistId = $playlistId;
$this->latestEpisode = $latestEpisode;
$this->expirationDate = time() + 86400;
// get current time + 24 hours
}
public function getLatestEpisode() {
return $this->latestEpisode;
}
public function getPlaylistId() {
return $this->playlistId;
}
public function isExpired() {
return $this->expirationDate < time();
}
}
Then, before polling the API, I look to see if I have a cached version available, and I only resort to the API if that cached version is expired.
$playlistCache = json_decode(get_option('playlist_cache_' . $playlistId));
if ($playlistCache->isExpired()) {
$items = $youtube->playlistItems->listPlaylistItems(
"id",
array(
"playlistId" => $playlistId,
"maxResults" => 50
)
);
while ($items->nextPageToken) {
$items = $youtube->playlistItems->listPlaylistItems(
"id",
array(
"playlistId" => $playlistId,
"maxResults" => 50,
"pageToken" => $items->nextPageToken
)
);
}
if ($items) {
$videoId = end($items->getItems()[0]->getId());
$video = $youtube->videos->listVideos("snippet", array('id' => $videoId))
$video = $video->getItems()[0];
$playlistCache = new PlaylistCache($playlistId, $video);
update_option('playlist_cache_' . $playlistId, json_encode($playlistCache)));
}
}
return $playlistCache->getLatestEpisode();
The other big change here is that my calls to listPlaylistItems() are requesting the id instead of the snippet.
According to the documentation, the snippet costs 2 units of the API quota while requests for the id are 0. So, I don't need to snag the snippet for every single item on every single page. I only need to grab the snippet of the final video in the results, which I can do with the more refined call to
$youtube->videos->listVideos()
With the addition of the PlaylistCache class I only reach out to the API when the cached version of the Playlist returns true on the $playlistCache->isExpired() call, so I only need to poll the entire playlist one time every 24 hours instead of 1 time every page load for every user.
It's still not exactly ideal, but as far as I can tell, it's the best option available right now.
Firstly, you need to get the channelId for the user via HTTP request:
Sample request:
https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername={0}&key={1}
where {0} is the USERNAME and key is you API key
Then, get the list of videos by calling 'PlaylistItems:list', it returns a collection of playlist items that match the API request parameters. You can retrieve all of the playlist items in a specified playlist or retrieve one or more playlist items by their unique IDs.
Sample request:
https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId={0}&key={1}
From there, you can create an array to get the last video in the playlist. Include max-results parameter, the max-results specifies the maximum number of results that included in the result set.
Typically, the latest video in a playlist in added to the front, not the end.

Displaying Output from Basic API (PHP)

So I am using an API (SendInBlue - a transactional email service) and I am trying to use the API to display a list of the users on my webpage.
Below, SendInBlue has given me sample code to use, however when I put them together I just get a blank screen.
I know this is a total beginner question... but how do I put these 2 pieces of code together so that it actually displays the list of contacts on my website?
Thank you so much!!
EXAMPLE
require('../mailin.php');
$mailin = new Mailin("https://api.sendinblue.com/v2.0","your access key");
$data = array( "listids" => array(1,2),
"timestamp" =>"2015-05-22 14:30:00",
"page" => 1,
"page_limit" => 2
);
var_dump($mailin->display_list_users($data));
SAMPLE OUTPUT
{
"code":"success",
"message":"Retrieved details of all users for the given lists",
"data":{
"data":[
{
"blacklisted":0,
"email":"email1#domain.com",
"id":1,
"listid":[1],
"blacklisted_sms":1,
"last_modified" : "2015-05-22 15:30:00"
},
{
"blacklisted":1,
"email":"email2#domain.com",
"id":2,
"listid":[1,2],
"blacklisted_sms":0 ,
"last_modified" : "2015-05-25 19:10:30"
}
],
"page":1,
"page_limit":2,
"total_list_records":100
}
}
Ok I figured this out. I turned every attribute into a variable like so...
$subscriberemail = $getemails['data']['data'][$number]['email'];
This took ages to figure out!

Yii restful API, how to modify return results from model

I followed this tutorial to set up my back end server based on Yii framework and then this tutorial to set up my API and everything is working as it should.
But I am not sure how to accomplish the next step:
My return array right now is pulling records that look like this:
{
"id": 1,
"user_id": 1,
"description": "This is a summary of article 1",
"status": 2,
"type": 1,
"created_at": 1426210780,
"updated_at": 1426365319
}
The value for 'type' is '1' in the db, but I want to store all the possible values of 'type' in another table like this:
1 : Red
2 : Blue
3 : Green
And then I want the JSON returned via my API to contain "type":'red' instead of "type":1. I assume I need to override something in my Model, but I can't figure out what to override or with what.
I'm happy to read through tutorials or documentation but I'm such a beginner at this that I'm not sure what terms to search for. Thanks for your help!
Have a look at models and their relationships to other models, this will allow you to get the information you need.
http://www.yiiframework.com/doc/guide/1.1/en/database.arr
Once the relationship is working correctly you should be able to get the colour from the original model.
Although this is from a earlier version of Yii it may help you understand how the models will interact as well
http://www.yiiframework.com/wiki/285/accessing-data-in-a-join-table-with-the-related-models/
#Burrito's response provided documentation but I want to give the full solution for other searchers:
First, I needed to set up a model for 'Type'.
Second, I needed to declare the relationship between 'Report' (my main model) and 'Type' like this (in my Report model):
public function getType()
{
return $this->hasOne(Type::className(), ['id' => 'type']);
}
(I'm not sure if that step is necessary, but the documentation makes it seem necessary.)
Third, I created getTypeName (in Report model), to get the name of the type based on the ID:
public function getTypeName($type = null)
{
return Type::findOne($type)->name;
}
Lastly, in my apiController, I modified the function that I am using to get all records to include a loop for each record that called getTypeName:
protected function findAllReports()
{
// get all reports
$reports = Report::find()
->asArray()
->all();
if( $reports ){
$i = 0;
// loop through each report
foreach($reports as $report){
$model = new Report();
// add a new key/value pair to each report array, populate with getTypeName and pass the type ID to it as a parameter
$reports[$i]['typeName'] = $model->getTypeName($reports[$i]['type']);
$i++;
}
return $reports;
} else {
// error or no results
}
}
For reference, the other routine needed here is the action that the API hits, which calls findAllReports():
public function actionList()
{
$reports=$this->findAllReports();
$this->setHeader(200);
echo json_encode(array('status'=>1,'data'=>$reports),JSON_PRETTY_PRINT);
}
Finally, now if I called [url]/api/list, I get an array of reports, including the typeName.

Getting Like and Comment

I'm using facebook PHP SDK , facebook api version 2.2.
I want to display the user news feed. I'm using the following api get this.
$facebookConncetion->api("$oauthUserId/home",
'GET',
array("access_token" => $accessToken,
"limit" => '15',
"comments.limit" => 10,
"likes.limit" => 10
)
);
But it returns all the post in the user home page with 10 comment and 10 likes and it does not return summary of like and comment. How can I format this api to get the like and comment summary per post?
You have to add .summary(true) and .filter(stream) to the like and comment request just like you added the limit.
Summary will return something like this:
"comments" : {
"data" : [ ARRAY OF COMMENTS ] },
"paging" : { PAGING CURSORS/URLS }.
"summary" : {
"total_count" : NUMBER OF COMMENTS
}
},
Adding .filter(stream) will return ALL comments/likes. With out this there may be some missing due to Facebook filtering them out due to their low "story" value. It will also order all comments/likes in true chronological order.
https://developers.facebook.com/docs/graph-api/reference/v2.2/object/comments
Look under "Modifiers" works with both comments and likes.

Categories