Set Description, Draft and Permalink using Blogger API with PHP - php

I really need your help with this matter. I'm looking for a solution for about 3 months now, but really the Blogger API is not easy to deal with because Blogger don't even provide examples.
I can create and publish new posts with PHP script and I have done all things, but I can't set the Post's description, permalink, or even making the new post as draft.
The following is a piece of my code that creating the post.
<?php
$mypost = new Google_Post();
$mypost->setTitle('My Post Title');
$mypost->setContent('This is My Content');
$mypost->setLabels( array( 'News','Weather', 'Media' ) );
$mypost->setCustomMetaData('My_CUSTOM_META_DATA' . time()); // Nothing changed
$mypost->setcustomMetaData('This is the description for you'); //Nothing Changed
$mypost->setDescription('New Description'); // Nothing Changed
$mypost->setUrl('testseturl'); // Nothing Changed
$mypost->setPublished('2021-08-27T23:07:00-07:00'); // Worked as Schedule post
$data = $blogger->posts->insert('My BlogID', $mypost);
echo "<pre>";
var_dump($data);
echo "</pre>";
?>
As you can see I can't set the permalink and I tried several thing such as adding the full URL, and also adding only the custom permalink text + html, but I failed.
I tried also the description several times, but every time I found the description's post empty.
Also I can' set the post as Draft and I have to do this manually from the blog itself.
Blogger doesn't provide any help docs for PHP, and the new Beta client library on github is for all Google products and I wasn't able to use it. I use the library Google API PHP Client 0.6.7 found here although it's deprecated.
The only topic I found in this blog, and it's the same code that I use, but he didn't mentioned anything about permalink, draft, or description.
Please help me as you can.
Thanks.

permalink
Unfortunately there is no way to set custom permalink to the posts using Blogger api, even the official "Try this API" tool don't have this feature, your code is fine it's just Blogger don't support it.
custom description
I don't think there is a way to add custom description as well, setDescription is not a valid method, you can check all the supported methods here
draft post
to create a post draft you can do it like this
$optParams = array('isDraft' => true);
$data = $blogger->posts->insert('My BlogID', $mypost, $optParams);

Related

Google Drive PHP method listFiles and get return 'thumbnailLink' NULL

I'm using the PHP V2 API. I requested full access (scope: https://www.googleapis.com/auth/drive). I also tried adding all of the different scopes to no avail.
I'm fully able to retrieve all files and list them but the thumbnail link is always null. Same with 'hasThumbnail'.
I tried the API explorer on https://developers.google.com/drive/v2/reference/files/get#examples and it shows me the thumbnail links correctly.
The relevant code can be boiled down to this:
$drive = new Google_Service_Drive($this->client);;
$files = $drive->files->listFiles($parameters)->files;
This is the response from the API explorer.
The response from my code (for the same ID) is:
Found the solution. It took 5 hours to run into this such simple solution.
Not many fields show by default, you must specify which fields you want populated.
The modified basic query now is:
$this->drive->files->listFiles([
'fields' => 'nextPageToken, files(thumbnailLink, webViewLink)'
])->files;

Include Likes and Share in meta on Wordpress

Site URL: http://intulife.de/blog/
Hi,
I want to change the meta of a post in Wordpress from ("0 Kommentare") as it is right now (see website link) to this picture ("0 Kommentare . 10 Likes . Teilen").
"Kommentare" mean "Comments" in German
"Teilen" means "Share" in German
This should include a connection to facebook for every post.
I did a lot of research but couldn't find any plugin that seemed to include the desired functionality. I might need to hard code something but my php knowledge is very limited.
I hope you guys can give me some hints in which direction I should go to reach the desired goal.
You can use Facebook graph API SDK to find the no. of likes on each post and include that javascript on each post you write.
here is the sample code of how you can do it but before that, you have to register for Facebook API on facebook developer console.
FB.api(
"/{object-id}/likes",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
If you need more help comment below i will be more than happy to help

wordpress make changes to post api

We are using wordpress for blogs (hosted via Godaddy). I am not a wordpress developer and hence this basic question. We have the wordpress post api like blog.domainname.com/wp-json/wp/v2/posts. This returns a json object of most of the fields. Now i have added a custom field to be returned with this object. i have seen lot of videos and study on what changes that needs to be done especially the one here.
https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
My Question is - Where do I make these changes? What file do I need add these changes? I am using WP as an admin. I installed a File Explorer plugin and I am able to see three main folders - wp-admin, wp-content, wp-includes.
Is there a particular file i need to make changes? Based on my learning - i wrote the following snippet. not sure where to add this :(
function addCustomField_register_fields() {
register_rest_field('post',
'custom_Field_name',
array(
'get_callback' =>'get_custom_field',
'update_callback' => null,
'schema' => null
));
}
function get_custom_field($object, $field_name , $request) {
return get_post('custom_field');
}
add_action('rest_api_init', 'addCustomField_register_fields');
Also would appreciate if you can let me know if my method is correct.
Typically theme customisations are added to the functions.php file in the root directory of your active theme.
As for your code, what are you trying to do? Your callback in particular doesn't look like it will work. get_post() loads a WordPress post by ID. 'custom_field' isn't a valid post ID, so this will always fail.

Display Number of Facebook Likes as Text

I'm trying to create a widget like the Facebook widget found on this site. I'm not sure how they've done it but somehow they're pulling in the number of Facebook likes from their page via the API. I've found a few examples online but none seemed to work. Is it possible someone could point me in the direction of how I can display the number of Facebook likes (for a page) as text?
Please note that the site I need it for is Wordpress so either an existing plugin or just PHP code will work!
This is how you can do it in php:
$fb_handle = "GideonShalwickUpdates";
$graph_url = "https://graph.facebook.com/".$fb_handle."?fields=likes";
$get_data = file_get_contents($graph_url);
$get_json = json_decode($get_data);
$likes = $get_json->likes;
echo $likes;

Wordpress share twitter via twitpic

my question a little complicated.
I want to share a featured image which is in a post on my wordpress site to twitter.
But there a important point. i want to share a picture with twitpic because of people can see this image in twitter without open my web site.
i get api from twitpic, and i use this code (link)
but twitpic or this code cannot accept a url to upload twitpic and get a link.
$resp = $twitpic->upload(array('media'=>'$a2', 'message'=>'get_the_title()'));
if i wrote $a2 = "ex.jpg" its working,
if i wrote $a2 = "http://www.ex.com/ex.jpg" not working
then i try that;
<?php
$a1 = $_SERVER['DOCUMENT_ROOT'];
// ex image remove 18 chr from begining http://*******.com/wp-content/uploads/2013/04/2012-10-17-23.48.34.jpg
$kisalt1 = $imageshare[0]; // wordpress featured image fxn ex: http://*******.com/wp-content/uploads/2013/04/2012-10-17-23.48.34.jpg
$kisalmis = substr($kisalt1,18,9999);
$a2 = $a1.$kisalmis;
// echo $a2; => /home/*******/public_html/wp-content/uploads/2013/04/bu-terste-bir-islik-var-panpa.jpg
?>
but it stil give same error.
Unable to find or read file
how can i get ride of this?
summary => i want to this => wordpres featured image to twitpic for share twitter like image which can open without click a link.
Edit: I just tried deleting this because I saw that you said that http://www.ex.com/ex.jpg doesn't work for you. But then I thought this might still be helpful (to someone), and for some reason the comments option didn't show up for me, so here it is again. Sorry if it doesn't help though.
What you need is just the post_thumbnail url, not the full image tag.
http://wordpress.org/support/topic/getting-post-thumbnail-url
The relevant post is the one with this code block:
$a2 = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
Does it work if you add that?
-Andrew
Another edit...I just came across this post on the Wordpress StackExchange site: https://wordpress.stackexchange.com/questions/83137/post-thumbnail-relative-link-and-html-modify
Does it work if you provide TwitPic with a relative link location?

Categories