我正在尝试将Google SignIn添加到my website,但我看不到任何问题,但如果我看到de Page源代码,我会看到此错误:
致命错误:在 /home/u289995868/public_html/es/php/glogin/app/classes/GoogleAuth.php中的非对象上调用成员函数createAuthUrl() 26
此档案的代码:
<?php
class GoogleAuth
{
protected $client;
public function __construct(Google_Client $googleClient = null)
{
$this->client = $googleClient;
if($this->client)
{
$this->client->setClientId('xxxxxxxx');
$this->client->setClientSecret('xxxxxxxx');
$this->client->setRedirectUri('http://barreeeiroo.ga/es/php/glogin/index.php');
$this->client->setScopes('email');
}
}
public function isLoggedIn()
{
return isset($_SESSION['access_token']);
}
public function getAuthUrl()
{
return $this->client->createAuthUrl();
}
}
?>
Index.php代码:
<?php
require_once 'app/init.php';
$googleClient = new Google_Client();
$auth = new GoogleAuth();
?>
... Here there is some code for navbar and other, not important
<h1>Prueba de Login de Google</h1>
<?php if(!$auth->isLoggedIn()): ?>
<a href="<?php echo $auth->getAuthUrl(); ?>">Iniciar Sesión</a>
<?php else: ?>
Ya has iniciado sesión
<?php endif; ?>
如果您想查看错误,请转到this website并查看源代码
答案 0 :(得分:0)
您必须从
更改import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JLayeredPane {
static JFrame frame;
static Main main;
static Dimension screenSize;
public Main() {
JPanel backPanel = new BackPanel();
JPanel frontPanel = new FrontPanel();
add(backPanel, new Integer(7));
add(frontPanel, new Integer(8));
new Thread(() -> {
while (true){
repaint();
}
}).start();
RepaintManager.currentManager(backPanel).markCompletelyClean(backPanel);
}
public static void main(String[] args) {
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame = new JFrame("Game"); // Just use the constructor
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
main = new Main();
frame.add(main, BorderLayout.CENTER);
frame.pack();
frame.setSize(screenSize);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public class BackPanel extends JPanel{
public boolean drawn = false;
public BackPanel(){
setVisible(true);
setOpaque(false);
setSize(screenSize);
JLabel test1 = new JLabel("Test1");
JLabel test2 = new JLabel("Test2");
add(test1);
add(test2);
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.red);
g.fillRect(0, 0, screenSize.width, 200);
System.out.print("Reccursion");
}
}
public class FrontPanel extends JPanel{
public FrontPanel(){
setVisible(true);
setOpaque(false);
setSize(screenSize);
JLabel test = new JLabel("Test");
add(test);
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.blue);
g.fillRect(0+screenSize.width/2, 0, screenSize.width/4, 300);
}
}
}
到
$auth = new GoogleAuth();
如果您检查$auth = new GoogleAuth($googleClient);
的构造函数:
GoogleAuth
您会看到默认为public function __construct(Google_Client $googleClient = null)
。这意味着如果不向构造函数传递任何内容,则null
参数将为$googleClient
。
快速RDD:
null
的实例,不传递任何参数,并将对象放入GoogleAuth
;
$auth
,null
为$googleClient
; null
设为GoogleAuth::$client
的值(所以,$googleClient
); null
;
GoogleAuth::getAuthUrl()
(由于GoogleAuth::$client->createAuthUrl();
为GoogleAuth::$client
,所以它几乎就像您在呼叫null
; 最后一步使人们更容易理解错误。