如何在另一个文件的另一个类中调用php方法?

如何在另一个文件的另一个类中调用php方法?,php,function,class,curl,Php,Function,Class,Curl,我在包含HTML的“index.PHP”文件中有PHP代码。目的是通过Google目录API进行身份验证。这是代码的设置: <?php // Admin Google API settings // Portal url: define("CALLBACK_URL", "http://localhost/los-api/google/index.php"); //Callback URL define("AUTH_URL", "https://accounts.google.com

我在包含HTML的“index.PHP”文件中有PHP代码。目的是通过Google目录API进行身份验证。这是代码的设置:

<?php

// Admin Google API settings
// Portal url:


define("CALLBACK_URL", "http://localhost/los-api/google/index.php");  //Callback URL
define("AUTH_URL", "https://accounts.google.com/o/oauth2/v2/auth");   //Used to get CODE (not Token!)
define("CLIENT_ID", "***.apps.googleusercontent.com");  // Personal
define("CLIENT_SECRET", "***");  // Personal
define("SCOPE", "https://www.googleapis.com/auth/admin.directory.device.chromeos 
https://www.googleapis.com/auth/admin.directory.user 
https://www.googleapis.com/auth/admin.directory.orgunit"); // Depends on what you want to do.
define("APIURL_DIRECTORY","https://www.googleapis.com/admin/directory/v1/customer/");  // For Google 
   Directory actions
     define("CUSTOMER_ID","***");       // Personal, see: ....? voorbeeld
   define("TOKEN_URL","https://oauth2.googleapis.com/token");   // URL to get Token (not code).

// Initiate code for access token
  if(isset($_GET["code"])){
   //DEBUG:  echo "Code: ".$_GET["code"];
    $url = TOKEN_URL."?";
  $url .= "code=".$_GET["code"];
 $url .= "&grant_type=authorization_code";
   $url .= "&client_id=". urlencode(CLIENT_ID);
   $url .= "&redirect_uri=". urlencode(CALLBACK_URL);
 $url .= "&client_secret=". urlencode(CLIENT_SECRET);

  $response = json_decode(exeCurl($url,"POST"), true);
 if(isset($response)){
   if(array_key_exists("access_token", $response)) {
    $access_token = $response;
     setcookie("LOStoken", $response['access_token'], time() + (86400 * 30), "/");  // 86400 = 1 day
    }
  }
} else {

  if(isset($_POST['gettoken'])){
    $url = AUTH_URL."?";
    $url .= "response_type=code";
    $url .= "&client_id=". urlencode(CLIENT_ID);
     $url .= "&scope=". urlencode(SCOPE);
    $url .= "&redirect_uri=". urlencode(CALLBACK_URL);
我如何做到这一点?通过继承?或者,要导入“curl.php”,就需要文件、活动类(由于@IncredibleHat for suggest的名称空间),并根据需要使用它

require 'curl.php'; $curlclass= new \CURL\cURL; echo $curlclass->exeCurl($url,"GET");

需要“curl.php”$curlclass=新卷曲;echo$curlclass->exeCurl($url,“GET”)是您搜索的?我尝试了此操作,但随后收到以下错误消息:致命错误:在C:\wamp64\www\losapi\index2.php第37行的C:\wamp64\www\losapi\index2.php中找不到类“curlclass”,是否缺少分配上的命名空间<代码>$curlclass=new\CURL\CURL旁注:我真的要重命名名称空间或类。。。太相似了;)@难以置信我将名称空间重命名为“requests”
require 'curl.php'; $curlclass= new \CURL\cURL; echo $curlclass->exeCurl($url,"GET");