Include Likes and Share in meta on Wordpress - php

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

Related

Set Description, Draft and Permalink using Blogger API with 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);

Google analytics event tracking - make the reports user friendly

GA: content>event>overview>event label.
I am using download tracker and I would like to make my reports "user friendlier",
the problem is, "this.href" function provide the "label" section in GA the name, which in that case takes the whole url (href="http://nameTheWebsite*/wp-content/uploads/2010/07/somethingToRead.pdf") and I would like to see only "somethingToRead.pdf" in my report.
the tracking code is:
_gaq.push(['_trackEvent','Download','PDF', this.href]);"
I am using WP.
now, I did some homework, and I believe that substr(this.href , -10) function could help but I don't know how to do it right.
Any help would be highly appreciatedׄ
Thanks in advance.
Gal
substr(this.href, -10) will only work correctly, whenever the filename is accidentially 10 characters long.
A more sophisticated solution would be something like this:
var page = this.href.splitOnLast('/'); // this should return an array with two elements: path and filename
page = (page.length > 1) ? page[1].substr(1) : page[0]; // just in case there is no / in the this.href
_gaq.push(['_trackEvent','Download','PDF', page]);
Now you should get "somethingToRead.pdf" in your Google Analytics tracking.

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;

In wordpress I am manipulation 404 response. I want to give the response before 404 error is given to google

May be the question in title is not explaining what exactly I want. So I will explain one logic and then ask what problem I am getting from that.
We are using wordpress.
We have 2 categories Option1(Having 64 different values) and Option2(Having 8 different values). We wanted url like ourdomain/Option1/Option2 depending on users location. And data on that url will be specific according to that Option1 and Option2. We dont wanted all this 64*8 actual wordpress pages to be created.
So after searching much on net we had one solution that I implemented one plugin for routing.
IN that code snippet was as follow.
function site_router() {
global $route,$wp_query,$window_title;
error_reporting(E_ALL);
if ( $wp_query->is_404 )
{
$wp_query->is_404 = false;
$cUrl="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$targetUrl="";
switch($cUrl)
{
/* According to condition I had written diffent cases like below.
*/
default :
{
include(get_template_directory() . "/home.php" );
$template =locate_template('pagepath/home.php');
$window_title = 'dynamically it will come';
if ($template) {
load_template($template);
die;
}
}
}
}
}
add_action( 'wp', 'site_router');
So by this my purpose was fulfilled successfully.
But now problem is that google is saying they are getting back a 404 error. I think obviosly it will give as after it gives the error we are doing all template loading and all stuff.
So Can any body guide me how can I do this before that 404 response is given to google.
I posted the question on wordpress stackexchange and got the answer over there. the link is as below.
https://wordpress.stackexchange.com/questions/70345/in-wordpress-i-am-manipulation-404-response-i-want-to-give-the-response-before

Manage Facebook Page tab apps via Open Graph API?

I have been investigating the Facebook Open Graph API. There is a "manage pages" extended permission which allows publishing to a user's Facebook Page news feed/wall via "impersonation". This is nice functionality, but is there anything more you can do through the API?
Specifically, I would like to be able to Add or Remove a "Tab" application from a user's Page via the API. Right now it's complicated to guide a user through the process of adding a tab app to their business (or Place) Facebook Page, and it would be AWESOME if they could just grant my app permission and I could add the app for them with the API.
Basically I am wondering if the API allows for true "page management", or just posting to the Page.
Anyone have any experience with this?
Is the best I can do pointing them to the "add.php" page with the "page" GET variable (e.g. http://www.facebook.com/add.php?api_key=xxxx&pages=1&page=xxxxxx)? This works OK for ADDING a tab application, but there is nothing at all to help them REMOVE an application from their Page so far as I know.
Thanks!
It is worth noting now, for anyone viewing this question (which is celebrating it's 1st birthday!), that Facebook significantly upgraded their API functionality back in July 2011. You can now Add, Remove, Rename, Reorder and set tabs as Default via the Open Graph API. The blog post is here:
https://developers.facebook.com/blog/post/524/
And the official documentation is here:
https://developers.facebook.com/docs/reference/api/page/#tabs
What Facebook does NOT have yet is a new API method for creating new tab apps, or for changing the tab icon. This is a big step though!
UPDATE: There is bug on the new bug tracker to follow about creating apps in the API if you want to follow it and see what they do: http://developers.facebook.com/bugs/295627350461318
There's a way to do it via the API. We finally got it to work, after many hours of sweat and tears :)
You can add a tab to a page without leaving your app. Here's a snippet of code that we used for that. We get a list of pages that a user manages, show them in a drop down and ask them to select what page they want to add our "my agent profile" tab to.
And the final product looks something like this - http://www.facebook.com/pages/Jennifer-Anderson-Real-Estate-Agent/185071901564573?sk=app_253956901293839
protected void btnAddTab_Click(object sender, EventArgs e)
{
if (ddlPage2.SelectedIndex >= 0)
{
FaceBookPages page = FaceBookPages.LookupByPageID(long.Parse(ddlPage2.SelectedValue));
if (page == null)
throw new NPlaySysException("FaceBookPages is null.");
AnalyticLog log = new AnalyticLog();
log.EventID = FBCommon.Events.AddAgentAppTabID;
log.UserID = UserID;
log.EventTime = DateTime.Now;
log.Update();
string result = FacebookSvc.AddTab(Web.AgentAppID, "me", page.AccessToken);
if (result.Equals("true"))
{
FaceBookPages.UpdateAgentProfileAdded(page.PageID, true);
List<FaceBookPages> notTabbedPages = FaceBookPages.LookupAgentProfileNotAddedByUserID(UserID);
imgStep3.ImageUrl = StepDoneImagePath;
divStep3.Attributes["class"] = StepDoneCssClass;
phStep3.Visible = false;
Step3Done = true;
btnCloseStep3.Visible = false;
if (notTabbedPages.Count > 0)
btnEditStep3.Visible = true;
else
btnEditStep3.Visible = false;
}
else
{
lblErrorAddTab.Text = "Failed to add your profile to page.";
Web.EmailError(string.Format("FacebookSvc.AddTab Failed. result={0}<br />UserID={1}<br />PageID={2}", result, UserID, page.PageID));
}
}
}
Yes, the best you can do is direct them to the add.php url. You can't do anything to help them remove the app.
The good news is that the user used to have to go through the add process AND physically decide to "enable" the tab by finding it in the tab dropdown on the page. Facebook has recently changed that and it seems that the tab is now immediately enabled after a user adds the app to their page.
As for "has_added_app" that works... sorta. It will tell you if the app is added to the page, but it won't tell you if the tab is enabled. For example, a user can disable the tab but still technically have the app installed on the page. Therefore "has_added_app" will return true even though the tab isn't actually visible.

Categories