I'm trying to fetch emails from gmail using PHP and CodeIgniter, and an OAuth2 library. I have already got OAuth2 set up to get the users access token, etc. I can get the users info by doing
public function get_user_info(OAuth2_Token_Access $token)
{
$url = 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&'.http_build_query(array(
'access_token' => $token->access_token,
));
$user = json_decode(file_get_contents($url), true);
return array(
'uid' => $user['id'],
'nickname' => url_title($user['name'], '_', true),
'name' => $user['name'],
'first_name' => $user['given_name'],
'last_name' => $user['family_name'],
'email' => $user['email'],
'location' => null,
'image' => (isset($user['picture'])) ? $user['picture'] : null,
'description' => null,
'urls' => array(),
);
}
What I want to do now is fetch some emails. I've googled for some code on how to get emails but the only thing I can see is https://mail.google.com/mail/feed/atom/. I found this on the Google OAuth2 Playground but I can't figure out how to use it apart from navigating to it directly.
Can anyone give me some suggestions? Ideally I want to fetch emails that are not just new (this seems to be what the link above does).
Using a REST-based interface you can currently only get the unread messages feed. If you want to access all emails of a user, you have to use IMAP. Google developed a method to do IMAP/SMTP authentication using OAuth2 that you can use.
Related
is it possible to do realtime voice call using nexmo/vonage with PHP or Javascript via web browser?
i used library called nexmo/laravel.
This sample code that i used:
$nexmo = Nexmo::calls()->create([
'to' => [[
'type' => 'phone',
'number' => '855969818674'
]],
'from' => [
'type' => 'phone',
'number' => '63282711511'
],
'answer_url' => ['https://gist.githubusercontent.com/jazz7381/d245a8f54ed318ac2cb68152929ec118/raw/6a63a20d7b1b288a84830800ab1813ebb7bac70c/ncco.json'],
'event_url' => [backpack_url('call/event')]
]);
with that code i can send text-to-speech, but how can i do realtime voice conversation person to person?
From the code you shared above, it looks like you might not have instantiated a client instance of the Nexmo PHP SDK, which is necessary to do so. You make an outbound call with an instantiated and authenticated client.
For example, first instantiate a client with the following, supplying the file path to your private key file, your application ID, your API key and your API secret. You can obtain all of those from the Dashboard
$basic = new \Nexmo\Client\Credentials\Basic('key', 'secret');
$keypair = new \Nexmo\Client\Credentials\Keypair(
file_get_contents((NEXMO_APPLICATION_PRIVATE_KEY_PATH),
NEXMO_APPLICATION_ID
);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic, $keypair));
Then, once you have a credentialed client, you can then invoke the $client->calls() methods on it. For example:
$client->calls()->create([
'to' => [[
'type' => 'phone',
'number' => '14843331234'
]],
'from' => [
'type' => 'phone',
'number' => '14843335555'
],
'answer_url' => ['https://example.com/answer'],
'event_url' => ['https://example.com/event'],
]);
You can find more information on using the PHP SDK on GitHub. You can also find code snippets, tutorials, and more instructions on our developer portal.
I have a working google chatbot that can send a message to a specific room that the chatbot is subscribed to using the following code:
$client = new Google_Client();
$client->setAuthConfig('../service-account.json');
$client->addScope('https://www.googleapis.com/auth/chat.bot');
$service = new Google_Service_HangoutsChat($client);
$message = new Google_Service_HangoutsChat_Message();
$message->setText('#Leon Vismer Testing a message.');
$message->setAnnotations([$annotation]);
$service->spaces_messages->create('spaces/SPACE_REFERENCE', $message);
However what I am trying todo is direct the message to a specific user inside the room using a mention. I tried using annotations but that does not seem to work. I get a notification of a new message inside the room but the #mention is not a proper annotation to the specific user.
I tried using:
$user = new Google_Service_HangoutsChat_User([
'name' => 'users/NUMBER_TO_THE_USER',
'displayName' => 'Leon Vismer',
'type' => 'HUMAN',
]);
$annotation = new Google_Service_HangoutsChat_Annotation([
'type' => 'USER_MENTION',
'startIndex' => 1,
'length' => strlen('#Leon Vismer'),
'userMention' => new Google_Service_HangoutsChat_UserMentionMetadata([
'user' => $user,
'type' => 'MENTION',
])
]);
Can a chatbot in a way initiate a conversation to a specific user like this?
I'm authenticating my users on my web service and then creating Firebase custom token via php-jwt:
// Requires: composer require firebase/php-jwt
use Firebase\JWT\JWT;
// Get your service account's email address and private key from the JSON key file
$service_account_email = ...;
$private_key = ...;
function create_custom_token($uid, $is_premium_account) {
global $service_account_email, $private_key;
$now_seconds = time();
$payload = array(
"iss" => $service_account_email,
"sub" => $service_account_email,
"aud" => "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
"iat" => $now_seconds,
"exp" => $now_seconds+(60*60), // Maximum expiration time is one hour
"uid" => $uid,
"claims" => array(
"premium_account" => $is_premium_account
)
);
return JWT::encode($payload, $private_key, "RS256");
}
But the users that I authenticate this way, don't show the administrator-friendly "Identifier" and "Providers" fields in the "Authentication" panel in the Firebase Console:
The first two are users that I authenticated via this custom authentication process, and the last one is a user that I authenticated directly via Google.
How can I populate the "Identifier" and the "Providers" fields for users created via custom authentication?
The "Providers" column will only display an icon if the information attached to a user matches one or more of the the given providers in the "Sign-In Methods" section (https://console.firebase.google.com/project/_/authentication/providers).
Custom providers don't have a distinct icon, and Firebase wouldn't know what to display in the "Identifier" column (the UID is already in its own column at the end).
However, you do have some control for the display of the columns by creating them in advance (meaning: before signing them in for the first time), or by updating the user information after the user entry has been created.
I prepared an example showing which combination of fields leads to which display:
Please note:
The display name has no effect: if it is the only data provided, the user is considered anonymous.
Email + Password match the "Email/Password" Provider
Phone Numbers will alway match the "Phone" provider
The icons for a matched provider will be displayed in the column, even if a provider has been disabled.
Emails and Phone numbers have to be unique. If your application allows multiple users with the same email address/phone number, you will get into trouble, if you just want to see more information about the users of your Firebase project.
You can create and update users via the Firebase Auth REST API, but I would suggest to use one of the official Firebase Admin SDKs SDK to do it - in case you want to stick to PHP, I happen to know an unofficial one: kreait/firebase-php (Documentation) (Disclaimer: I'm the maintainer of the PHP SDK :) ).
On a non-technical note: I wouldn't bother too much with the user list in the Firebase Web Console: use the Firebase CLI tool or one of the official (or unofficial ;) ) Admin SDKs to create an overview that meets your needs.
You mentioned in the Bounty Annotation that you asked this in the Firebase Slack Community without an answer - you can find me and other PHP developers in the #php channel. I enabled notifications for the channel, so please feel free to join if you have further questions.
FYI, this is the code I wrote with the PHP SDK to create the data for the screenshot above:
<?php
declare(strict_types=1);
use Kreait\Firebase;
use Kreait\Firebase\Util\JSON;
require_once __DIR__.'/vendor/autoload.php';
$serviceAccount = Firebase\ServiceAccount::fromJsonFile(__DIR__.'/service_account.json');
$firebase = (new Firebase\Factory())
->withServiceAccount($serviceAccount)
->create();
$auth = $firebase->getAuth();
// Remove all users
foreach ($auth->listUsers() as $user) {
$auth->deleteUser($user->uid);
}
// Simulate custom auth
$ct = $auth->createCustomToken('a-custom-auth');
$r = $auth->getApiClient()->exchangeCustomTokenForIdAndRefreshToken($ct);
echo JSON::prettyPrint($auth->getUser('a-custom-auth'));
echo JSON::prettyPrint($auth->createUser([
'uid' => 'displayname-only',
'displayName' => 'Jérôme Gamez',
]));
echo JSON::prettyPrint($auth->createUser([
'uid' => 'email-only',
'email' => 'jerome#example.org',
]));
echo JSON::prettyPrint($auth->createUser([
'uid' => 'email-and-password',
'email' => 'jerome#example.com',
'password' => 'password'
]));
echo JSON::prettyPrint($auth->createUser([
'uid' => 'phone-only',
'phoneNumber' => '+49-123-1234567',
]));
echo JSON::prettyPrint($auth->createUser([
'uid' => 'email+name+phone',
'email' => 'jerome#example.net',
'displayName' => 'Jérôme Gamez',
'phoneNumber' => '+49-123-7654321',
]));
echo JSON::prettyPrint($auth->createUser([
'uid' => 'email+name+password+phone',
'email' => 'jerome#example.de',
'displayName' => 'Jérôme Gamez',
'password' => 'example123',
'phoneNumber' => '+49-321-7654321',
]));
I use Laravel 5 to develop an app and I use Mailchimp for adding subscription. I use Mailchimp v.3 . I can make a list using this code:
$mailchimp = new Mailchimp(xxxxxxxxxxxx-xx);
$contact = [
'company' => $request['campaign'],
'address1' => $request['address'],
'city' => $request['city'],
'state' => $candidate->userCandidate->state,
'zip' => $request['zip'],
'country' => $request['country'],
'phone' => $request['phone'],
];
$campaign_details = [
'from_name' => $request['from_name'],
'from_email' => $request['from_email'],
'subject' => $request['remind_text'],
'language' => 'English'
];
$data = [
'name' => Auth::user()->name . ' Campaign',
'contact' => $contact,
'permission_reminder' => $request['remind_text'],
'campaign_defaults' => $campaign_details,
'notify_on_subscribe' => $request['from_email'],
'notify_on_unsubscribe' => $request['from_email'],
'email_type_option' => false,
'visibility' => $request['visibility'],
];
$list = $mailchimp->post('lists', $data);
I use this library drewm/mailchimp. My code on subscribing is this:
$mailchimp = new Mailchimp($api_key);
$subscriber = [
'email_type' => 'html',
'email_address' => $email,
'language' => 'English',
'status' => 'subscribed',
'merge_fields' => ['zip' => $zip]
];
$result = $mailchimp->post('lists/' . $list_id . '/members', $subscriber);
And I can successfully subscribe it. This is my question how to verify an email first before will be recorded on mailchimp list to avoid spammer. I read on mailchimp that they have DOUBLE OPT-IN method but it is only available if you use their form.
My solution is to email first on subscriber and create a link for verifying and this solution can take time. Is there another solution on this? Does Mailchimp have method to acquire this?
I don't have any idea on Mailchimp API. However, you just have to set up an email validation flow first. In this way, all emails will not be considered as "spam" in your records. Then you're free to do any email tasks without worrying if it is valid or not.
The quick answer to your question is to set the status to "pending" instead of "subscribed", but you should check out MailChimp's docs on managing subscribers with API v3 for more details.
MailboxValidator does have an easy import feature to grab your list from MailChimp for email validation purposes. Then it automatically updates your MailChimp list once the validation process is done.
https://www.mailboxvalidator.com/resources/articles/how-to-import-email-list-from-mailchimp/
$ln->fetch("POST","/v1/groups/1483367/posts", "")
I am new to linkedin Api i am not understanding how the things are working in linkedin api.
Linkedin share code is below i come to know how this is working as below but i need to know how to work with group post(i am already a member of that group and i am login to linkedin while posting my post to group)
$ln->fetch('POST','/v1/people/~/shares',
array(
'comment' => 'Hello Linkedin',
'content' => array(
'title' => 'SimpleLinkedIn (SLinkedin)',
'description' => 'Open source OAuth2 Implementation for PHP and linkedin.',
'submittedUrl' => 'https://github.com/EJTH/SLinkedIn/'
),
'visibility' => array('code' => 'anyone' )
)
));
This page describes how to POST to a LinkedIn group that the authenticated user is a member of: https://developer.linkedin.com/documents/groups-api#create