【问题标题】:Editing google contacts and adding new google contacts through codeigniter application通过 codeigniter 应用程序编辑谷歌联系人并添加新的谷歌联系人
【发布时间】:2015-08-03 07:26:01
【问题描述】:

下午好,我刚刚创建了一个可以导入 google 联系人并使用 OAuth2 显示它们的页面。我为此使用了 google-api-php-client。我可以成功获取所有联系人的详细信息并显示它们。但是,我的主要目标是能够编辑 google 联系人的详细信息,并根据特定的用户操作从我的 codeigniter 应用程序中添加新的 google 联系人。我想知道我需要写什么函数以及在相应的视图中做什么。请帮我。非常感谢您。

代码:

<?php 
error_reporting(E_ALL);
ini_set("display_errors", 1);

session_start(); ?>
<!DOCTYPE html>
<html class="no-js" lang="en"/>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Google Contacts API</title>
</head>

<body>
<h2>Google Contacts API v3.0</h2>
<?php
require_once 'lib/google-api-client/autoload.php';
require 'lib/google-api-client/Config.php';
require 'lib/google-api-client/Google_Client.php';

$client_id = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbb.cccccccccccc.com';
$client_secret = 'e3fsfds4gfg23ha93kmKFkfgK';
$redirect_uri = 'http://ccccccccccccccccccc.com/rddddddddddd/index.php';

$client = new Google_Client();
$client -> setApplicationName('contact');
$client -> setClientid($client_id);
$client -> setClientSecret($client_secret);
$client -> setScopes('https://www.google.com/m8/feeds');
$client -> setRedirectUri($redirect_uri);
$client -> setAccessType('online');

if (isset($_GET['code'])) {
    $client->authenticate($_GET['code']);
    $_SESSION['token'] = $client->getAccessToken();
    header('Location: ' . $redirect_uri);
}

if(!isset($_SESSION['token']))
{
    $url = $client->createAuthUrl($_SESSION['token']);
    echo '<a href="' . $url . '">Import Google Contacts</a>';
}else{
        $client->setAccessToken($_SESSION['token']);
        $token = json_decode($_SESSION['token']);
        $token->access_token;
        $curl = curl_init("https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=1000&access_token=" . $token->access_token);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        $contacts_json = curl_exec($curl);
        curl_close($curl);
        $contacts = json_decode($contacts_json, true);
        $return = array();
        foreach($contacts['feed']['entry'] as $contact){
            $return[] = array(
            'name' => $contact['title']['$t'],
            'email' => isset($contact['gd$email'][0]['address']) ? $contact['gd$email'][0]['address'] : false,
            'phone' => isset($contact['gd$phoneNumber'][0]['$t']) ? $contact['gd$phoneNumber'][0]['$t'] :false,
            );
        }
        echo "<pre>";
        var_dump($return);
        echo "</pre>";
    }       
?>

</body>
</html>

请随时询问更多详细信息。

【问题讨论】:

    标签: php oauth-2.0 google-oauth google-api-php-client google-contacts-api


    【解决方案1】:

    要更新联系人,首先检索联系人条目(您已经完成),修改数据并向联系人的编辑 URL 发送授权的 PUT 请求,并在正文中包含修改后的联系人条目。

    网址:https://www.google.com/m8/feeds/contacts/userEmail/full/{contactId}

    要创建新联系人,请向用户的联系人提要 URL 发送授权的 POST 请求,并在正文中包含联系人数据。

    网址:https://www.google.com/m8/feeds/contacts/{userEmail}/full

    【讨论】:

    • Muhammad Sumon Molla Selim - 那么我必须在模型中添加什么功能
    • Muhammad Sumon Molla Selim - 我有一个带有引导框对话框页面的预订页面,用户可以输入新的客户数据并保存它,我还需要检查 Google 联系人是否已经存在 - 每次作为用户可以输入现有客户 - 还有一个客户页面,可以通过引导框对话框编辑并保存当前客户详细信息 - 更改需要反映在 Google 联系人中 - 谢谢
    • Muhammad Sumon Molla Selim - 我有正常的视图、模型和控制器 - 请给我方向 - 谢谢
    • 你能分享你的代码吗?这将有助于我以正确的方式指导您。
    • Muhammad -ok
    猜你喜欢
    • 2020-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多