Html url 中的 google plus 共享和参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11868291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
google plus share and parameters in url
提问by user1502291
I use Google+ to share some links on my page and there is a problem when I try to share an URL containing parameters. Example:
我使用 Google+ 在我的页面上分享一些链接,但当我尝试分享包含参数的 URL 时出现问题。例子:
http://google.com?n=somethink&link=p/1393007&i=images/icons/gplus-16.png
When you put this URL into the field at this page:
当您将此 URL 放入此页面的字段中时:
https://developers.google.com/+/plugins/share/
...and click on the share
button, you can't see information about page like name, picture and description. But when you delete the dot before "png", then Google shows data about the page.
...然后点击share
按钮,您看不到有关页面的信息,如名称、图片和描述。但是当您删除“png”之前的点时,Google 会显示有关该页面的数据。
The same thing happens when you write the '
symbol anywhere in the URL. I can't find any information about this error in Google Help Pages. It works when I use an URL like this:
当您'
在 URL 中的任何位置写入符号时,也会发生同样的事情。我在 Google 帮助页面中找不到有关此错误的任何信息。当我使用这样的 URL 时它会起作用:
http://google.com?n='&link=p/1393007&i=images/icons/gplus-16.png
...but it isn't very elegant solution.
...但这不是很优雅的解决方案。
How to write clean URLs?
如何编写干净的 URL?
回答by Sid
currently G+ share supports only two parameters: url, for the target url, and hl, for a language code.
目前 G+ share 只支持两个参数:url,用于目标 url,和 hl,用于语言代码。
https://plus.google.com/share?url=http://www.stackoverflow.com
https://plus.google.com/share?url=http://www.stackoverflow.com
Alternatively, you can add OpenGraph tags to the head of your page to specify the same fields like this: (haven't tested yet)
或者,您可以将 OpenGraph 标签添加到页面的头部以指定相同的字段,如下所示:(尚未测试)
<meta property="og:title" content="..."/>
<meta property="og:image" content="..."/>
<meta property="og:description" content="..."/>
回答by Chirag Shah
Make sure you URL encode the link you want to share on Google+ via the Google+ share link.
确保对要通过 Google+ 分享链接在 Google+ 上分享的链接进行 URL 编码。
For example: if you want to share the link http://example.com?a=b&c=d
, first URL encode the link to look like:
例如:如果你想分享链接http://example.com?a=b&c=d
,首先对链接进行 URL 编码,如下所示:
http%3A%2F%2Fexample.com%3Fa%3Db%26c%3Dd
Now you can share the link on Google+ through the share link:
现在您可以通过分享链接在 Google+ 上分享链接:
https://plus.google.com/share?url=http%3A%2F%2Fexample.com%3Fa%3Db%26c%3Dd
回答by Gunasekar
function googleplusbtn(url) {
sharelink = "https://plus.google.com/share?url="+url;
newwindow=window.open(sharelink,'name','height=400,width=600');
if (window.focus) {newwindow.focus()}
return false;
}
var url="www.google.com";
googleplusbtn(url);
回答by antelove
The share link is intended for native client applications, Flash applications, highly privacy-sensitive sites, and others who may not be able to use the +1 or share button. Adding the following markup to your site will include a simple icon which will pop open a share dialog for your visitors.
共享链接适用于本机客户端应用程序、Flash 应用程序、高度隐私敏感的网站以及其他可能无法使用 +1 或共享按钮的网站。将以下标记添加到您的网站将包括一个简单的图标,该图标将为您的访问者打开一个共享对话框。
<a href="https://plus.google.com/share?url=https://stackoverflow.com/questions/11868291/google-plus-share-and-parameters-in-url" onclick="javascript:window.open(this.href,
'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"><img
src="https://www.gstatic.com/images/icons/gplus-64.png" alt="Share on Google+"/></a>
回答by user6838991
The answer is very poor. You should use api for login then share content.
答案很差。您应该使用 api 登录然后共享内容。
require_once 'google-api-php-client-master/src/Google/Client.php';
$client = new Google_Client();
$client->setClientId('YOUR_CLIENT_ID');
$client->setClientSecret('YOUR_CLIENT_SECRET');
$client->setRedirectUri('YOUR_REDIRECT_URI');
$plus = new Google_PlusService($client);
$authUrl = $client->createAuthUrl();
$visibleActions = array(
'http://schema.org/AddAction',
'http://schema.org/ReviewAction');
$authUrl .= '&request_visible_actions=' .
urlencode(implode(' ', $visibleActions));
print '<a href="' . $authUrl . '">Sign in with Google</a>';