Where to find sample C# .NET code for Google's People API? - google-people-api

I have an installed app that uses .NET and the Contacts API. I'm trying to convert to the People API. I'm having trouble getting started and finding a sample that shows how to use People API with the .NET library. For example, the samples listed under the Peoples API documentation doesn't include .NET. Where can I find a .NET sample for the People API?

Start with this ;)
https://googleapis.dev/dotnet/Google.Apis.PeopleService.v1/latest/api/Google.Apis.PeopleService.v1.html
Get the nuget called Google.Apis.PeopleService.v1 https://github.com/googleapis/google-api-dotnet-client
Also, I'm sure you have seen this https://developers.google.com/people/v1/profiles
It has some .net examples.
What exactly are you trying to accomplish?
I am just about to complete converting an app that used contacts API to people API using a service account for the company.
ps. I can't copy the whole namespace in the answer hense answer with a link.
Edited: 20210608
Person person = new Person();
person.EmailAddresses = new List<EmailAddress>();
person.EmailAddresses.Add(new EmailAddress() { Type = "work", Value = "sample#domain.com" });
person.Names = new List<Name>();
person.Names.Add(new Name() { FamilyName = "Lname2", GivenName = "Fname" });
// link to peopleService code can be found in the comments
// it's basically initializing PeopleServiceService with service account credentials
Person retVal = peopleService.People.CreateContact(person).Execute();

Related

How do I get a Registration object to register Classroom API for notifications?

I am attempting to have my Google Classroom API enable push notifications. I have successfully created a topic in Cloud Pub/Sub to have this work. But the docs are officially confusing me on the part where I'm supposed to get a Registration object to pass to Classroom#registrations().create().
I have been looking at the docs for a little while now, and I can't find the place where a Registration should be instantiated. Perhaps I don't understand the concept well enough. I would highly appreciate someone's further explanation.
Haha, I'm such a silly goose. I put more effort into reading the docs, and this finally clicked.
I'm using Java.
registrations().create takes a Registration object, which is just a representation of a JSON REST Registration object in the API. It's just an abstraction to be used in the client library. This is a good place to get you started understanding this
Here's some example code I wrote now that I understand how this works:
NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
Classroom service = buildClassroomService(httpTransport);
final var pubSupTopic = new CloudPubsubTopic()
.setTopicName("my-topic");
final var courseWorkChangesInfo = new CourseRosterChangesInfo()
.setCourseId("------------");
final var feed = new Feed()
.setFeedType("COURSE_WORK_CHANGES")
.setCourseRosterChangesInfo(courseWorkChangesInfo);
Registration notificationsRegistration = new Registration()
.setFeed(feed)
.setCloudPubsubTopic(pubSupTopic);
pubSupTopic.setFactory(JSON_FACTORY);
courseWorkChangesInfo.setFactory(JSON_FACTORY);
feed.setFactory(JSON_FACTORY);
notificationsRegistration.setFactory(JSON_FACTORY);
final var response = service.registrations().create(notificationsRegistration);

How do I register a custom NameResolver with the new HostBuilder in WebJobs SDK 3.x?

There are a lot of examples on the internet on how to do this with the old JobHost, but none I can find with HostBuilder.
Thanks,
George
For now I didn't found detailed documentation on the new HostBuilder.
However looks like we could use this code to do it. You could find it on github.
.ConfigureServices(services =>
{
// add some sample services to demonstrate job class DI
services.AddSingleton<ISampleServiceA, SampleServiceA>();
services.AddSingleton<ISampleServiceB, SampleServiceB>();
}
And there is an answer about it, which uses the same service to implement it, you could try it.

Is there an equivalent way of doing 'lb soap' programmatically with loopback?

According to documentation on loopback, lb soap creates models of underlying soap based datasource. Is there a programmatic way to do this? I want to do it programmatically to facilitate a dynamic soap consumption through dynamically created models and datasources.
Disclaimer: I am a co-author and maintainer of LoopBack.
Here is the source code implementing the command lb soap:
soap/index.js
soap/wsdl-loader.js
Here is the code that's generating models definition and method source code:
exports.generateAPICode = function generateAPICode(selectedDS, operationNames) { // eslint-disable-line max-len
var apis = [];
var apiData = {
'datasource': selectedDS,
'wsdl': selectedWsdl,
'wsdlUrl': selectedWsdlUrl,
'service': selectedService.$name,
'binding': selectedBinding.$name,
'operations': getSelectedOperations(selectedBinding, operationNames),
};
var code = soapGenerator.generateRemoteMethods(apiData);
var models = soapGenerator.generateModels(apiData.wsdl, apiData.operations);
var api = {
code: code,
models: models,
};
apis.push(api);
return apis;
};
As you can see, most of the work is delegated to soapGenerator, which refers to loopback-soap - a lower-level module maintained by the LoopBack team too. In your application, you can use loopback-soap directly (no need to depend on our CLI tooling) and call its API to generate SOAP-related models.
Unfortunately we don't have much documentation for loopback-soap since it has been mostly an internal module so far. You will have to read the source code to build a better understanding. If you do so, then we would gladly accept contributions improving the documentation for future users.

Create a web service that can answer to WhatsApp messages

I'm trying to understand if it's possible to create a web service that can send and answer to WhatsApp messages. I searched on the web and I found the WhatsAPI,
I guess this solution work fine, but with the actual version of WhatsApp it's not possible to get the nickname, the sender, the imei and the password.
To get them I set up a Linux PC in which I installed mitmproxy to sniff the web traffic of a Samsung Galaxy S4. By using mitmproxy I can see the web traffic generated by the phone, so I tried to register to WhatsApp (with an another SIM), but in mitmproxy I can't see the data I need for WhatsAPI.
Does anyone knows if it's possible to get the password by using another way?
If it exist can you suggest me a way? Do you think it's possible to do that or it's better to use Telegram or Wechat (they have public API)?
For Java, you can try WhatsUp
For Python, see YowsUp.
Beware that WhatsApp threatens legal action against many of these library developers and does not officially support using the service this way.
I have also spoken directly with WhatsApp representatives who have said no commercial API use of WhatsApp is acceptable.
Also note that bulk messaging is against the WhatsApp terms of service.
There used to be a PHP implementation at WhatsAPI, and another Java implementation, WhatsApi4J. Both are no longer available due to legal threats.
For .NET you use https://github.com/mgp25/Chat-API-NET
download installer for generate password https://github.com/mgp25/WART from this link
string nickname = "Nickname";
/* Your number in the format CCAANNNNNNNNN
* C - Country Code
* A - Area Code
* N - Phone number */
string sender = "***************"; //phone number
string password = "*****************"; // Obtain it with WART or Yowsup
WhatsApp wa = new WhatsApp(sender, password, nickname, true);
wa.OnConnectSuccess += () =>
{
Console.WriteLine("Connected");
wa.OnLoginSuccess += (phoneNumber, data) =>
{
Console.WriteLine("Connection success!");
wa.SendMessage("**************"/* Number */, "Hello World!");
Console.WriteLine("Message sent!");
};
wa.OnLoginFailed += (data) => {
Console.WriteLine("Login failed: {0}", data);
};
wa.Login();
};
wa.OnConnectFailed += (ex) =>
{
Console.WriteLine("Connect failed: {0}", ex.StackTrace);
};
wa.Connect();
Console.WriteLine("END");
Console.ReadLine();
wart app maybe works good for you.
WART
WhatsApp Registration Tool
Uses token generator created by Jake
Uses WhatsApiNet fork by me
Requires .NET Framework 4 or Mono Framework (mono-complete on Linux)
This tool is used to register new phonenumbers and can also be used to retrieve a new password for already registered numbers.
The registration identity is auto-generated by the program based on the phone number.
The optional (and highly recommended) password field is used as salt when generating the identity. This will generate a unique identity hash which cannot be replicated unless you know the password.
Leaving the password field blank will generate an identity hash of just the phone number, which can be easily replicated and is highly insecure.
If these answers were helpful to you, please consider saying thank you in a more constructive way

How execute a FQL Insights query with Facebook Graph API

I try without success to execute a FQL query using Graph API to get the value of Insights counters.
Does anyone know how I can do this?
I use "Facebook C# SDK" version 5.4.1, C# 4.0.
If I use C# sample code provided in the documentation
var fb = new FacebookClient(m_accessToken);
dynamic result = fb.Query("SELECT name, uid FROM user WHERE uid= me()");
I receive a good response
{"name":"","uid":100002632407830}
With the same syntax, If I request "pages_fans" Insights counter and use library 5.4.1
var fb = new FacebookClient(m_accessToken);
dynamic result = fb.Query("SELECT metric, value FROM insights WHERE object_id=6176018219 AND metric='page_fans' AND end_time=end_time_date('2011-12-31') AND period=period('lifetime')");
I receive always an empty response
{[]}
With the same code but with library 5.2.1
I receive always a good response
{[{"metric":"page_fans","value":"125535"}]}
It is the same problem described here : Error with FQL query with library 5.4.1 but with another syntax.
Currently I use FQL Insights queries using REST API (with libary 5.2.1) but I want to migrate to FQL Insights queries using the Graph API (with library 5.4.1) because the REST API is deprecated.
Where is the bug:
In my syntax request?
In the "Facebook C# SDK" library?
On Facebook server?
Best regards.
I made a request with the Facebook Graph API Explorer
https://graph.facebook.com/fql?q=SELECT metric, value FROM insights
WHERE object_id=6176018219 AND metric='page_fans' AND
end_time=end_time_date('2011-12-31') AND period=period('lifetime')
I receive always an empty response.
{
"data": [
]
}
It is a Facebook's bug.
A bug was created about it on Facebook : http://developers.facebook.com/bugs/232510993491615?browse=search_4f08c675cce9d2265724293
I found another way to retrieving the info which works reliably
I found another way of retrieving insights which seems to be reliable.
documentation found here http://developers.facebook.com/docs/reference/api/insights/.
with more options to allow format and period changes - below example.
https://graph.facebook.com/2439131959/insights/application_active_users/[period]?format=json&since=[timestamp]&until=[timestamp]&access_token=[access_token]
period is day, month, week, lifetime.
timestamp has to be a valid PST midnight only.
access_token = could be.
1. nothing for the metrics that don't need permission.
2. app_id|secret_code or
3. your authentication token granted that you have access to the insight data of the application or pages (ie owner or insight users).
C# sdk example:
FacebookClient fbClient = new FacebookClient([appID], [secret]);
DateTime untilDate= (new DateTime([Now].Year, [Now].Month, [Now].Day));
DateTime sinceDate= (new DateTime([Now].Year, [Now].Month, [Now].Day)).AddDays(-1);
TimeSpan t = (untilDate- new DateTime(1970, 1, 1));
int timestampUntil = (int)t.TotalSeconds;
t = (sinceDate- new DateTime(1970, 1, 1));
int timeStampSince = (int)t.TotalSeconds;
var result = (IDictionary<string, object>)fbClient.Get([appID] + "/insights/" + [metricID] + "/" + [period] + "?format=json&since="+timeStampSince+"&until="+timestampUntil );
Console.WriteLine(result["data"]);
Make sure you have the correct permissions when you get your Access Token
<fb:login-button perms="read_insights"></fb:login-button>
This issue related to Facebook C# SDK.
Probably best thing you can do is file a bug on codeplex, and replace usage of end_time_date to "time in seconds" and period to "lifetime".