Can I fetch a phone number from Twitter Digits callback? - c#

Is it possible to fetch user's phone number from Twitter Digits callback? I'm using http version and javascript to send SMS with twitter digits.
I only see next information response headers:
{"oauth_echo_headers":{"X-Verify-Credentials-Authorization":"OAuth oauth_consumer_key=\"gmoaaZhEG88hMQUdpWHnF1IAz\", oauth_nonce=\"3375731039-FmyAQgjhQG9rljUaXO3jBbiryF7dFQHeVL5oxu4gmoaaZhEG88hMQUdpWHnF1IAz1437035638029\", oauth_signature=\"TTbPlgipWdaNCSblfx0qznz%2B2Fc%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1437035638\", oauth_token=\"3375731039-FmyAQgjhQG9rljUaXO3jBbiryF7dFQHeVL5oxu4\", oauth_version=\"1.0\"","X-Auth-Service-Provider":"https://api.digits.com/1.1/sdk/account.json"}}

Once you receive the credentials authorization header, you can query the server directly to receive attributes from the Digits service. Per the docs:
/* Validate and log user in. */
function onLogin(loginResponse){
// Send headers to your server and validate user by calling Digits’ API
var oAuthHeaders = loginResponse.oauth_echo_headers;
var verifyData = {
authHeader: oAuthHeaders['X-Verify-Credentials-Authorization'],
apiUrl: oAuthHeaders['X-Auth-Service-Provider']
};
$.post('/verify', verifyData)
.done(function(){ window.reload(); });
}
You can see a sample of this in action in the Cannonball web demo.

May be its late but it can easily be achieved by putting following code wherever you want to fetch phone number:
String phone = Digits.getActiveSession().getPhoneNumber();

Related

Google My Business API to fetch Reviews

I want to know how can I use GMB API to fetch reviews. According to google documentation we have to make a GET request to https://mybusiness.googleapis.com/v3/{name=accounts/*/locations/*}/reviews
But what is meant by {name=accounts/*/locations/*} and from where we can get the value of accounts & locations.
Also this requires OAuth 2.0. If I get a access_token then GET request will be like this:-
https://mybusiness.googleapis.com/v3/{name=accounts/*/locations/*}/reviews?access_token=token
This is very confusing. Can somebody tell me how to use GMB API correctly to fetch google reviews.
Using Google OAuth 2 Playground
For testing acquisition of Google reviews
Create a project
Console.cloud.google.com
Sign in as {projectowner}#google.com
Select a project from the dropdown in the header or click new project
Go to APIs & Services in the left menu
Enable the Google My Business API; this requires validation by Google and may take a couple of days. They will email you.
Go to developers.google.com/oauthplayground
Using the settings gear, set OAuth flow to Client-side and click Use your own OAuth credentials
Get the client id from console.developers.google.com/apis and paste it in
Put this into scope: https://www.googleapis.com/auth/plus.business.manage and authorize it with {projectowner}#gmail.com
Exchange auth code for token
To get the account name:
Set Request URI to https://mybusiness.googleapis.com/v4/accounts and send a Get request
Copy the entire string value at “name”: not including quotes; it may be 20+ numeric digits
To get location names:
Set Request URI to https://mybusiness.googleapis.com/v4/accounts/{paste account name here}/locations where {paste ... here} is the account name you copied
The returned JSON contains all of your locations
Copy the location names including quotes and commas to a temporary holding document; they will be used in a JSON array in the next step
To get multiple locations’ reviews
a. Set Request URI to https://mybusiness.googleapis.com/v4/accounts/{account name here}/locations:batchGetReviews and the Method to Post
b. Set Request Body to
{
"locationNames": [
"accounts/999999999999999999999/locations/88888888888888888888",
"accounts/999999999999999999999/locations/77777777777777777777",
.
.
.
"accounts/999999999999999999999/locations/11111111111111111111"
],
"pageSize": 200,
"orderBy": "updateTime desc",
"ignoreRatingOnlyReviews": false
}
using the account names you saved from the location JSON for each line of the array
If you have more than 200 total reviews you will have to add "pageToken": string into the JSON body where string is a value returned in the preceding POST.
But what is meant by {name=accounts//locations/} and from where we can get the value of accounts & locations.
To get this details first get the account using the following API (https://mybusiness.googleapis.com/v4/accounts?access_token=#####)
Once you have the account list, fetch Account Location list using the following API (https://mybusiness.googleapis.com/v3/" + name + "/locations) in the response of this API you will get the {name=accounts/*/locations/*}.
Also this requires OAuth 2.0. If I get a access_token then GET request will be like this: https://mybusiness.googleapis.com/v3/{name=accounts/*/locations/*}/reviews?access_token=token
Yes, that is correct.
Let me know if this work's for you.

Zendesk - How to get users based on roles?

I am using Elizabeth's wrapper from https://github.com/mozts2005/ZendeskApi_v2
I want to pull a list of agents. I don't see any built in Function that will allow that.
I have tried using the endpoint of /api/v2/users.json?role=agent with the GetAllUsers() function but it still returns all of them.
Right now, I am going to add a custom field to be able to search for them, but that should not be the case, especially since Zendesk's API does have an option for returning users based on their role: /api/v2/users.json?role[]=admin&role[]=end-user
Can anyone help me out?
You can give a try to the Zendesk Search API:
from urllib.parse import urlencode
import requests
results = [] # Empty list to collect pagination results
credentials = 'your_zendesk_email', 'your_zendesk_password'
session = requests.Session()
session.auth = credentials
params = {
'query': 'type:user role:agent'
}
url = 'https://your_subdomain.zendesk.com/api/v2/search.json?' + urlencode(params)
while url:
response = session.get(url)
data = response.json()
results += data['results']
url = data['next_page'] # should return false according to the doc when the last page is reached
Useful resources:
zendesk api python tutorial
zendesk api pagination
Search endpoint seems to be supported also in the c# library you are using.

Passing Verified Number as CallerId in Twilio API with C#

I have following scenario:
1) Application asks the user to input a phone number.
2) Number is verified on the fly using AddOutgoingCallerId.
3) Application store the number in a session.
All this code is written in a web page say:
http://www.mysite.com/CallNumber.aspx
4) Application now use twilio api to initiate call using InitiateOutboundCall.
5) Using verb Twilio api collects a number and transfers the call to the url mentioned "action" attribute of gather verb.
Imagine it like:
6) Now I want to pass the value stored in session (mentioned in step 3) to be used by http://www.mysite.com/targetpage.aspx.
7) Now even though CallNumber.aspx and targetpage.aspx are on same server, targetpage.aspx always receives session value as null, because call to CallNumber.aspx will be made by a User and call to targetpage.aspx will be made by twilio api server, so there are two different calls.
My ultimate target is to pass the phone number of the user who initiates the call (say Customer1) to the called number, collected by using verb (say Customer 2) .as callerId.
I am adding dropbox link of the image which shows the scenario:
DropBox Link
How can I pass the Customer1's phone number as caller id to Customer 2, as keeping the phone number in session doesn't work (Because calls are initiated from different locations I guess) ?
Twilio evangelist here.
You could pass the phone number received by CallReceived.aspx to targetpage.aspx by appending it to targetpage.aspx as a querystring value:
var result = client.InitiateOutboundCall("+15555555555","+15556666666","http://www.mysite.com/targetsite.aspx?number=%2B15557777777");
Then in targetpage.aspx, you just use the Request object to get the number:
string number = request["number"];
Hope that helps.

What is the best way to <Dial> multiple phone numbers simultaneously using the Twilio C# Library?

I'm using the twilio-csharp helper library. I have a Twilio number, and when someone calls that number, I want to call multiple phones or endpoints like a Twilio Client endpoint and a few phone numbers all at the same time. What is the best way to accomplish this?
The workflow for this functionality looks like this: caller calls a Twilio phone number, Twilio looks up the Voice Request URL associated with that phone number, Twilio sends a TwiML request to the resource at that URL, the resource responds with TwiML instructing Twilio to <Dial> out to several phone numbers, Twilio then calls the phone numbers and connects the caller with the first person to pick up. Note that if you simultaneously <Dial> numbers, when the first phone picks up, the rest of the calls are cancelled.
There are a couple ways to simultaneously <Dial> phone numbers using the twilio-csharp library . The first way to simultaneously <Dial> is to use the DialNumbers method. As the name suggests, DialNumbers will only dial phone numbers, and will only take an array of strings.
The second way to simultaneously <Dial> numbers is to use the Twilio.TwiML.TwilioResponse.Dial(params, Twilio.TwiML.IDialNoun[] dialTargets) method. One of the benefits of using this method is that one can call phone numbers, sip addresses, and/or Twilio Client instances. One can also modify the call attributes, setting the the action URL, timeout limit, or any other dial attribute. Here's a usage example:
public ActionResult SimulDial()
{
var response = new TwilioResponse();
var dialAttributes = new { timeout = 10 };
var dialTargets = new IDialNoun[]
{
new Number("8021111111"),
new Number("8022222222"),
new Client("clientName")
};
response.Dial(dialAttributes, dialTargets);
return TwiML(response);
}
When Twilio receives this TwiML, Twilio will dial out to the three specified endpoints (the two numbers and one client). If no one picks up within 10 seconds, all dialing will be cancelled.

User Master Account to send SMS on behalf of a Sub Account

I'm developing a feature for our product that will allow users to send SMS messages via Twilio and we handle all of the account issues. We have our Master Account and all of our customers will be sub accounts under us.
In an effort to not have to keep track of 1000+ auth tokens, we decided to use our Master Account credentials to send the SMS message however we still want it to roll up under the sub account. According to Twilio, this shouldn't be an issue.
My problem is that there is very little (that I've found) documentation for the c# library they provide. I'm not sure if what I've done is the correct way to accomplish what I described above and since I'm on a trial account until the project is finished and can be rolled out to production I have no way of testing.
var twilio = new TwilioRestClient("Master SID", "Master Auth Token");
var response = twilio.SendSmsMessage(sender, recipient.ConvertToE164Format(), message, null, "Subaccount SID");
The comment on this overload isn't really clear on if passing the subaccounts SID here will send the message as if I had logged into their account and sent it.
// applicationSid:
// Twilio will POST SmsSid as well as SmsStatus=sent or SmsStatus=failed to
// the URL in the SmsStatusCallback property of this Application. If the StatusCallback
// parameter above is also passed, the Application's SmsStatusCallback parameter
// will take precedence.
The callback url will be the same across all accounts so I don't need/care about that value.
Short Version:
If I log in with my Master Account details but pass the subaccount SID in the SendSmsMessage() method, which account does the message come from?
Twilio support finally got back to me and confirmed my fears that this wouldn't work. I do have to pull the subaccount information down and reinstantiate the twilioRestClient with the new credentials which I was hoping I could get away with not doing. Just a few extra lines.
var twilio = new TwilioRestClient("Master SID", "Master Auth Token");
var subAccount = twilio.GetAccount("SubAccount SID");
var subAccountClient = new TwilioRestClient(subAccount.Sid, subAccount.AuthToken);
var response = subAccountClient.SendSmsMessage(sender, recipient.ConvertToE164Format(), message);
return response.Sid;

Categories

Resources