0

我正在尝试创建登录名并注销我使用了这里的代码

https://developers.google.com/appengine/docs/php/users/loginurls?hl=vi

所以我的代码看起来像

    <?php
require_once 'google/appengine/api/users/User.php';
require_once 'google/appengine/api/users/UserService.php';


use google\appengine\api\users\User;
use google\appengine\api\users\UserService;

$user = UserService::getCurrentUser();

if (isset($user)) {
    echo sprintf('Welcome, %s! (sign out)',
        $user->getNickname(),
        UserService::createLogoutUrl('/'));
} else {
    echo sprintf('Sign in or register',
        UserService::createLoginUrl('/'));
}

和我的 app.yaml

application: test
version: 1
runtime: php
api_version: 1
threadsafe: true

handlers:
- url: /stylesheets
  static_dir: stylesheets

- url: /images
  static_dir: images

- url: /scripts
  static_dir: scripts

- url: .*
  script: main.php
  login: required
  auth_fail_action: redirect

当我使用 Google PHP SDK 1.8.1 在本地运行应用程序时,出现很多错误并且页面无法加载。

ERROR:root:php failure (255) with:

<br />
<b>Warning</b>:  file_get_contents(): php_network_getaddresses: getaddrinfo failed: No such host is known.  in <b>D:\google_appengine 1.8.1\php\sdk\google\appengine\runtime\RemoteApiProxy.php</b> on line <b>92</b><br />
<br />
<b>Warning</b>:  file_get_contents(http://localhost:56354): failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known.  in <b>D:\google_appengine 1.8.1\php\sdk\google\appengine\runtime\RemoteApiProxy.php</b> on line <b>92</b><br />
<br />
<b>Fatal error</b>:  Uncaught exception 'google\net\ProtocolBufferDecodeError' with message 'Not initialized: logout_url' in D:\google_appengine 1.8.1\php\sdk\google\appengine\runtime\proto\ProtocolMessage.php:121
Stack trace:
#0 D:\google_appengine 1.8.1\php\sdk\google\appengine\runtime\proto\ProtocolMessage.php(88): google\net\ProtocolMessage-&gt;mergeFromString('')
#1 D:\google_appengine 1.8.1\php\sdk\google\appengine\runtime\RemoteApiProxy.php(109): google\net\ProtocolMessage-&gt;parseFromString('')
#2 D:\google_appengine 1.8.1\php\sdk\google\appengine\runtime\ApiProxy.php(42): google\appengine\runtime\RemoteApiProxy-&gt;makeSyncCall('user', 'CreateLogoutURL', Object(google\appengine\CreateLogoutURLRequest), Object(google\appengine\CreateLogoutURLResponse), NULL)
#3 D:\google_appengine 1.8.1\php\sdk\google\appengine\api\users\UserService.php(95): google\appengine\runtime\ApiProxy::makeSyncCall('user', 'CreateLogoutURL', Object(google\appengine\CreateLogoutURLRequest), Object(google\appengine\CreateLogoutURLResponse))
#4 D:\Google PHP\ in <b>D:\google_appengine 1.8.1\php\sdk\google\appengine\runtime\proto\ProtocolMessage.php</b> on line <b>121</b><br />

INFO     2013-06-20 22:00:49,384 server.py:593] default: "GET / HTTP/1.1" 500 -

知道 SDK 中出现了什么问题。

当我从服务器运行应用程序时,它不会创建注销链接未创建链接

4

1 回答 1

1

您在 apppot 中看到的错误是因为您实际上并未在 html 中包含生成的链接。

比较示例:

'Welcome, %s! (<a href="%s">sign out</a>)'

使用您的代码:

'Welcome, %s! (sign out)'
于 2013-06-20T18:45:55.397 回答