Cannot update user information using Google PHP API Client library - php

I am trying to update user phone numbers on Google Apps Directory. Currently I have the API able to retrieve information on user's but when I try to set their phone numbers it just silently fails. The values do not update in the directory. It is possible I may be just missing a method that actually sends the data but I have been unable to find such a method.
My current scopes are:
$scopes = array('https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.group', 'https://www.googleapis.com/auth/admin.directory.orgunit');
My attempts at saving phone numbers have been varied. I have tried:
$work_phone = new \Google_Service_Directory_UserPhone();
$work_phone->setType('work');
$work_phone->setValue($work_number);
$google_user->setPhones(array($work_phone));
And
$google_user->setPhones(array(array(
"type"=>"work",
"value"=>$work_number
)));
As well as a variety of values for the type array structures. Any help would be greatly appreciated.

In order to update the phone number in the directory, you need to send the information back to Google. With your code:
$google_user->setPhones(array($work_phone));
You are setting the object's phones array correctly. You still need to update that user however. You were correct when you said:
I may be just missing a method that actually sends the data
You would need to do something like this:
$work_phone = new \Google_Service_Directory_UserPhone();
$work_phone->setType('work');
$work_phone->setValue($work_number);
$google_user->setPhones(array($work_phone));
$serviceDirectory = new Google_Service_Directory($client);
$serviceDirectory->users->update($google_user);
Relevent API documentation can be found here: https://developers.google.com/admin-sdk/directory/v1/reference/users/update

Related

MailChimp sending incorrect user IDs

EDIT: There's a chance I may have been a complete bonehead and mistook USER:UID for the member's ID when in fact it may be referring to the account admin ID. I have changed it to simply include the member's email address as the last URI segment. Is that an acceptable approach?
I'm setting up an EDM in MailChimp that includes a link to a website form. The URL is structured like so:
http://domain.com/foo/*|LIST:UID|*/*|USER:UID|*
The idea is that some PHP on that page gets the member info using the list ID and the user ID in the API (3.0) endpoint for use in a cURL operation:
$url = 'https://us4.api.mailchimp.com/3.0/lists/' . $listid . '/members/' . $userid;
The retrieved data would then pre-populate the form so that the user could edit the information and submit to 1) store the record of the submission locally in the CMS, and 2) send a PATCH command to the API.
This worked fine in my testing with a different MailChimp account, but when switching over to the production account, the *|USER:UID|* merge tag started sending incorrect hashes. I even changed the list but the ID stayed the same, and neither IDs were valid MD5 hashes.
To be clear, this is not an issue with authorization, I correctly changed the credentials (API key and username) and data center in the URL. If I manually enter a valid user ID into the URL the information is retrieved successfully. I simply can't get the correct user IDs to be embedded in the email.
Additionally, my initial testing using PUT instead of PATCH failed if the entered email address was not found in the list, sending back a message to use PUT (which I was).
Yeah, passing the email address back to your page is likely the best option for you here.
I know this question is old, but perhaps you were looking for *|UNIQID|* instead of *|USER:UID|*? According to MailChimp's documentation:
*|UNIQID|* Pulls in the $member->email->unique_id; (API function).
If used in an email campaign, this tag will pull in your subscriber's
unique ID. It can also be used to create unique links for subscribers.
The merge tag you were using, *|USER:UID|*, simply says:
*|USER:UID|* Displays the "u" parameter from your hosted Mailchimp audience forms.
While their documentation does not specify what the "u" parameter is, this other stack overflow answer to a related question mentions that it is an identifier for your account, which is exactly the same conclusion you came to in your question's edit :)
Personally, I prefer to pass unique IDs as opposed to email addresses for the sake of privacy. Some of my clients put a high value on privacy and security so we do not pass any personally identifiable information (PII) where it could be intercepted.

PHP RESTful API to accept authentification

I am working on a PHP REST API. I would like require a user key to access the API. I am not sure how to do this though, do I just issue a key and have them send it in a POST or with GET on each API request? Please help me explain in the simplest of terms possible if you can, I know this is something a lot of people want to do and it confuses a lot of people not just myself.
Also I would like to be able to limit usage, I was thinking of storing each hit in a MySQL database or something in Memory even. I just saw this in the header of a Github API request
X-RateLimi-Limit 5000 and X-RateLimi-Remaining 4996 and the number decreases by 1 on each hit, is this some kind of built in limiter?
Just require clients to register with your site,
create a record in your CLIENTS table, issue them a unique, non easy to guess id
then with each api access require that id to be included in request, either in GET or POST on in the header.
Validate it with every request, return error code if id is not present or invalid.
For rate limiting you are correct, you need to have a separate table for storing count of requests per client and then generate these response headers with X-RateLimit counters.
It's not that hard, really.
I wrote an API that does that for my project, you are welcome to look at the source code, it's in the Api folder, here
https://github.com/snytkine/LampCMS/tree/master/lib/Lampcms/Api/
and entry point to API calls is this
https://github.com/snytkine/LampCMS/blob/master/www/api/api.php
url for adding new app is:
http://support.lampcms.com/index.php?a=editapp

How to create web API service in PHP [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Is it necessary to have a wsdl file for the creation of a webservice in php?
I want to create a web API.
My requirement is that I want to create to a way so that my customers would be able to insert/delete data from my website database, but I do not want the customers directly logged into my site. I want them to call my WSDL file URL via a client request, which will return the response to the customer.
I have heard that we can do so with the help of SOAP call or NuSOAP. I have tried several methods after doing some googling but have no success.
Can you please tell me the step by step instructions how I can achieve this.
Basically, What is an API?
If you understand how data goes from a HTML form to php code, then trust me you know all about API's. Here rather than talking forms, we talk about urls that are created at the end by those forms.
What are the Types of API?
There are two types of heavily used APIs for web services: SOAP and REST. Google is one of the major players with a SOAP based API while Yahoo (and most of their recent acquisitions) have taken the REST approach. More often than not, a “Web 2.0” service you come across today will probably be using REST.
How to create a REST API in PHP with Authentication Key to delete a value from database?
Let’s say we have a PHP class (manage.php) that helps us manage entries in a database:
class manage {
private $entryId;
function __construct($entryId) {
$this->entryId = $entryId;
}
function deleteEntry() {
//delete $this->entryId from database
}
}
On our own server, we might access this functionality like so:
require_once('manage.php');
$m = new manage(23);
$m->deleteEntry();
Easy enough for us, but how do we allow someone not on our server access to the same functionality? For that, we’ll create a third file to act as a buffer (or “interface”) between other developers and our class. Here’s an example of a file we might create to allow developers to access the delete function in our class, we’ll locate it at ‘api/delete.php’
require_once('manage.php');
if (hasPermission($_POST['api_key']) {
$m = new manage($_POST['entry_id']);
$m->deleteEntry();
}
This will allow users to send a POST request to us at http://example.com/api/delete.php with an api_key and an entry_id. You’ll notice the function is very similar to what we wrote on our own server except we check the POST api_key variable using a function to see if its authorized to access the database. We didn’t include that function here (hasPermission) for simplicity’s sake. In addition to what’s shown, you’d also have to find the user’s account based off of the api_key, put in some error checking and (if you want to make a good API) provide a properly formatted success or error response after the request. We’ll get into the success and error responses in a bit.
How To Design A Good API and Why it Matters?
I guess this video by Google can explain lot better than me. http://youtu.be/aAb7hSCtvGw
References:
http://en.wikipedia.org/wiki/Representational_state_transfer
http://en.wikipedia.org/wiki/SOAP
http://particletree.com/features/how-to-add-an-api-to-your-web-service/
http://www.webresourcesdepot.com/how-to-create-an-api-10-tutorials/
Google Search Result
Note: The answer is compilation of all references!!.

Getting the user_id through Foursquare Api V2

I'm working on a foursquare integration for a social good website, and I have everything working as I want it to, however I want to retrieve and store users foursquare user_id's so others can search for their friend. I've been searching all day, but I can't seem to find an end point, am I missing something? Or does this has to be done through user search? What is then best to use, as I have their email, and full name.
I am using jmathai's foursquare-async php libary. I think it should be easy but I just can't figure it out.
I've found the solution. To get an users' details you should use the end point "users/self". I had tried this before but got an error message. I think that was related to something else now.
After authenticating two lines are simply enough:
<?php
$fsObj->get("/users/self");
print_r($creds->response);
?php>
This gives an json array containing all relevant information on the user, including last checkins, name, and id. 'self' can here also be replaced by any user id you're authorized for on that moment.
For more information I'd recommend to visit Foursquare Api website

Is it possible to change the user status on Facebook, using the 'Official PHP Client Library'?

I downloaded the .php files from here, and I am able to take the first and last name or friend names, but now I want to update the status of a user.
I am following the RESTful API documentation, however I can't find a relevant method in the facebookapi_php5_restlib.php file. Am I missing something here, or this is not possible?
http://wiki.developers.facebook.com/index.php/Users.setStatus
with proper permissions you can use the users_setStatus() function to update the user's status.
basic call:
$result = $facebook->api_client->users_setStatus($status);
you can also use the stream.publish method:
http://wiki.developers.facebook.com/index.php/Stream.publish

Categories