Using the API to get google directory contacts - google-app-engine

I am a Google Apps customer and want to use the Contact API to search for a user in the company directory.
I am able to access contacts using for example:
feed = gd_client.GetContacts()
However the contacts this returns is only a subset of my contacts and is not those in the company directory.
Has anyone had experience of this or give me any pointers.

I think what you are looking for is the Domain Shared Contact API instead of the Contact API. Check this out (https://developers.google.com/google-apps/domain-shared-contacts/)
Try to run the get request against the domain, you should be able to retrieve your directory contacts instead of personal contacts (https://developers.google.com/admin-sdk/domain-shared-contacts/#Retrieving)

Try using Query to get result feed. You can specify max results to get in query. This way your result feed will be returned with more contacts in other groups as well.
URL FeedURL = new URL("https://www.google.com/m8/feeds/contacts/default/full");
Query MyQuery = new Query(FeedURL);
MyQuery.setMaxResults(200);
ContactFeed ResultFeed = MyService.query(MyQuery, ContactFeed.class);

Related

MsGraph get users filter to get only person account

Is there a way to list users and filter only real person account using MsGraph users API ?https://graph.microsoft.com/v1.0/users
Currently, it returns person but also conference rooms and others.
I see that you can retrieve persons you work with using people API:
https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/people?$filter=personType/class eq 'Person' and personType/subclass eq 'OrganizationUser'
Is there anything similar for users ?
Thanks you !
The current options are to either use the People API like you said or the List orgContacts endpoint from the Microsoft Graph Rest API Beta.
GET https://graph.microsoft.com/beta/contacts
This returns the list of organizational contacts for the organization.

Getting a users mailbox current history Id

I'd like to start syncing a users mailbox going forward so I need the most recent historyId of the users mailbox. There doesn't seem to be a way to get this with one API call.
The gmail.users.history.list endpoint contains a historyId which seems to be what I need, from the docs:
historyId unsigned long The ID of the mailbox's current history record.
However to get a valid response from this endpoint you must provide a startHistoryId as a parameter.
The only alternative I see is to make a request to list the users messages, get the most recent history id from that, then make a request to gmail.users.history.list providing that historyid to get the most recent one.
Other ideas?
Did you check out https://developers.google.com/gmail/api/guides/sync ?
Depending on what your use-case is, to avoid races between your current state and when you start to forward sync, you'll need to provide an appropriate historyId. If there were a "get current history ID" then anything between your previous state and when you got those results would be lost. If you don't have any particular existing state (e.g. only want to get updates and don't care about anything before that) then you can use any historyId returned (e.g. on a message or thread) as you mention.
Small example for C# users (mentioned in comments by #EricDeFriez).
Nuget package Google.Apis.Gmail.v1 must be installed. See also quickstart for .NET developers.
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
var req = service.Users.GetProfile("me");
req.Fields = "historyId";
var res = req.Execute();
Console.WriteLine("HistoryId: " + res.HistoryId);
This answer is related to the Java Gmail API Client Library using a service account.
I found that the gmail.users.getprofile() will not work as the object that it returns is of type Class Gmail.Users.GetProfile which does not have an interface to getting a historyId.
com.google.api.services.gmail.model.Profile actually has a getHistoryId() function, but calling service.users().getProfile() will return a Class Gmail.Users.GetProfileobject instead.
To get around this, I use the history.list() function which will always return the latest historyId as part of its response.
Gmail service = createGmailService(userId); //Authenticate
BigInteger startHistoryId = BigInteger.valueOf(historyId);
ListHistoryResponse response = service.users().history().list("me")
.setStartHistoryId(startHistoryId).setMaxResults(Long.valueOf(1)).execute();
I set the max number of results to be 1 to limit the unnecessary data that I get returned back and I will receive a payload that looks like:
{"history":[{"id":"XXX","messages":[{"id":"XXX","threadId":"XXX"}]}],"historyId":"123456","nextPageToken":"XXX"}
The historyId (123456) will be the current historyId of the user. You can grab that historyId using response.getHistoryId()
You can also see that the latest historyId is given in the response if you use the API tester for Users.history: list
https://developers.google.com/gmail/api/v1/reference/users/history/list

Serve multiple PayPal sellers from the same website

I have a website that does ticket sales. This website uses PayPal to process the payments. More specifically, I am using ExpressCheckout to process payments.
I have two sellers right now, and I cannot get them to both work at the same time.
Their sites are:
myapp.appspot.com/SellerA
myapp.appspot.com/SellerB
I have separate PayPal signature credentials for each seller in different config files:
acct1.UserName = sellera_api1.comcast.net
acct1.Password = <passwordA>
acct1.Signature = <signatureA>
acct1.UserName = sellerb_api1.comcast.net
acct1.Password = <passwordB>
acct1.Signature = <signatureB>
Here is the frustrating workflow that I am encountering:
1) Seller A works just fine, Seller B gets this error:
com.paypal.exception.InvalidCredentialException: Invalid userIdsellerb_api1.comcast.net
2) request new signature credentials for seller B and paste them into seller B's config file
3) Seller B works just fine, Seller A gets this error:
com.paypal.exception.InvalidCredentialException: Invalid userIdsellera_api1.comcast.net
4) request new signature credentials for seller A and paste them into seller A's config file
5) back to step 1
Any idea what could be happening here and how to fix this problem?
You might have to set them as two different accounts (like below) so that you make different API calls based on API user.
acct1.Username = sellera_api1.comcast.net
acct2.Username = sellerb_api1.comcast.net
Then you could call
setExpressCheckout(SetExpressCheckoutReq setExpressCheckoutReq, String apiUsername)
This probably not the best way to solve it and so I am very interested to see other solutions.

Google Custom Search and Passing along Querystring Variables

I am working on a web app project that has been in development for long time. The app has two sides, the majority of the site is publicly accessible. However, there are sections that require the user to be logged in before they can access certain content.
When the user logs in they get a sessionid (GUID) which is stored in a table in the database which tracks all sort for data about the user and their activity.
Every page of the app was written to look if this session id variable exists or not in the querystring. If a user tries to access one of these protected areas, the app checks to see if this sessiond variable is in the querystring. If i is not, they are redirected to the login screen.
The flow of the site moves has the user moving seamlessly from secured areas to non-secured areas, back and forth, etc.
So we did a test run with the Google Custom Search and it does an awesome job picking up all our dynamic content in these public areas. However, we have not been able to figure out how to pass the sessionid along with the search results IF the user is logged in already.
Is it possible to pas querystring variables that already exist in the url along with the search results?
As far as I know, this is not possible. Google doesn't give you the possibilty to modify the URL's of the Search Results in their Custom Search.
A possible solution would be to store your Session-Key to a Cookie, rather than passing it with every URL.
Use the parseQueryFromUrl function
function parseQueryFromUrl () {
var queryParamName = "q";
var search = window.location.search.substr(1);
var parts = search.split('&');
for (var i = 0; i < parts.length; i++) {
var keyvaluepair = parts[i].split('=');
if (decodeURIComponent(keyvaluepair[0]) == queryParamName) {
return decodeURIComponent(keyvaluepair[1].replace(/\+/g, ' '));
}
}
return '';
}
Select RESULTS ONLY option in the Look & Feel and it will provide you with the code.
www.google.com/cse/

DotNetNuke Retrieving UserInfo for the given UserID

Is there somthing in the dotnetnuke framework which will allow me to pass it a userId and it would return the UserInfo object filled with details of that userId.
If not what would be the normal way of doing this?
Try this (in DNN 5.x with C#)
private UserInfo _currentUser =
DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
Then use the UserInfo later...
int UserID = _currentUser.UserID
I used the way posted by bdukes with one modification: PortalId can be get from PortalSettings:
DotNetNuke.Entities.Users.UserInfo user = DotNetNuke.Entities.Users.UserController.GetUser(PortalSettings.PortalId, user_id, true);
To get the current user, as of version 7.3 all of the above have been deprecated. Now you need to use access the user info via the Instance property and the GetCurrentUserInfo() method, i.e.:
DotNetNuke.Entities.Users.UserController.Instance.GetCurrentUserInfo()
Hence you could get the UserId as so:
DotNetNuke.Entities.Users.UserController.Instance.GetCurrentUserInfo().UserID
So, given a user id, you could get the user's info like this:
UserController.GetUserById(PortalId,your_user_id)
Note that PortalId is a property provided by the DNN context, so you can simply type it as above.
I hope this helps.
I believe that DotNetNuke.Entities.Users.UserController has a method (GetUser) that will do that, if you also have a portal ID. Users can be shared across portals, so it's (apparently) necessary to know the portal for which you're requesting the user information before they can properly fill the UserInfo object.
If you only have a user ID and no portal ID, I'd first suggest that you see if you can get a portal ID, too. If not, you'll need to go to the database to get what you need. Ideally, you'll be in there as little as you can be (since the database isn't a guaranteed API). So, if you just do a quick query to get a portal ID for the user:
SELECT PortalID From {databaseOwner}{objectQualifier}UserPortals WHERE UserID = #userId
You can then use UserController.GetUser to retrieve what you need.
It's not return User ID what is the problem
Dim nowUser As UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo
response.write(nowUser)
If you need to get the current user it's simpler:
Dim nowUser As UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo
Just a note.

Resources