So I got access to the new o365 v2 api and it's working pretty good so far. I am however having trouble accessing any shared inboxes.
Even worse, there doesn't appear to be any error message being returned:
#odata.context = https://outlook.office.com/api/v2.0/$metadata#Me/Messages(Subject,ReceivedDateTime,SentDateTime,Sender,From,ToRecipients,CcRecipients,BccRecipients,ReplyTo,ConversationId,IsRead,InternetMessageId
[value] =
Has anyone ever tried this?
To clarify, this isn't for exchange, but outlook.com
It seems that you were using the delegate-token to request the message from the specific user for the messages in a shared box.
The Office 365 REST API only support app-level token to get the messages from the organization. The delegate-token only could get the messages of the delegatee user.
You can also consider using the EWS to retrieve the messages of shared box as a workaround.
Here is an example for your reference:
string userName = "";
string password = "";
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new NetworkCredential(userName, password);
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl(userName, RedirectionUrlValidationCallback);
FolderId SharedMailbox = new FolderId(WellKnownFolderName.Inbox, "sharedmailbox#consoto.onmicrosoft.com");
ItemView itemView = new ItemView(10);
var results = service.FindItems(SharedMailbox, itemView);
foreach (var item in results)
{
Console.WriteLine(item.Subject);
}
And if you want the Office 365 REST API to support this feature, you can also submit the feedback from here.
Related
I manage approximately 200 Google My business accounts, all being owned under an email XXX#YYY.com
I would like to use the Google My Business API using a PHP SDK to retrieve all types of stats regarding each accounts (ie. view per timeframe, view through map, view through SERP, etc...).
I did get the authorization to use the Google My Business API and I downloaded the php SDK: https://developers.google.com/my-business/samples/google-api-services-mybusiness-v4p9-php-rev-20210224-1.zip?hl=fr
I also created a service account (which I'm really not familiar with) in order to auth with the library.
Now here is my code :
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
// set the service account json file location manually
$client->setAuthConfig(__DIR__.'/../global/yyyyy-xxxx-xxxxxxxxxx.json');
$client->setApplicationName("yyyyyb");
// set the scope to access GMBs
$client->setScopes([
"https://www.googleapis.com/auth/business.manage"
]);
$this->client = $client;
$mybusinessService = new Google_Service_Mybusiness($client);
$accounts = $mybusinessService->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
echo "<pre>";
print_r($accountsList);
echo "</pre>";
$locationNames = array("Paris");
$insightReqObj = new Google_Service_MyBusiness_ReportLocationInsightsRequest();
$insightReqObj->setLocationNames($locationNames);
$basicReqObj = new Google_Service_MyBusiness_BasicMetricsRequest();
// datetime range is mandatory
// TODO :: validate to not allow more than 18 months difference
$timeRangObj = new Google_Service_MyBusiness_TimeRange();
$timeRangObj->setStartTime("2020-01-01T15:01:23Z");
$timeRangObj->setEndTime("2021-01-11T15:01:23Z");
$metricReqObj = new Google_Service_MyBusiness_MetricRequest();
$metricReqObj->setMetric('ALL');
$basicReqObj->setMetricRequests(array($metricReqObj));
$basicReqObj->setTimeRange($timeRangObj);
$insightReqObj->setBasicRequest($basicReqObj);
$allInsights = $mybusinessService->accounts_locations->reportInsights("accounts/XXXXXXXX",$insightReqObj);
echo "<pre>";
print_r($allInsights);
echo "</pre>";
There are two issues :
When I print the accountlist, I only find information about my service account, I was expecting a list of all the accounts managed by my email : XXX#YYY.com ; I realise that it makes no sense since I don't even know how to grant the service account access to the My Business account managed by this email.
Also AllInsignt generate an error :
How can I access the statistics of all the accounts managed by my Gmail account : XXX#YYY.com ?
I am using the Twilio PHP helper library.
I have several subaccount credentials stored in the database. Each subaccount usually has several outgoing caller ids associated with it.
I use the credentials for each subaccount to get the outgoingCallerIds.
From the data returned, I take the subaccount SID (AC) and the number SID (PN).
I follow the documentation and am receiving errors on each attempt to update master with the numbers from the subaccounts.
Caught exception: [HTTP 404] Unable to update record: The requested
resource
/2010-04-01/Accounts/ACxxxxxxxxxxxxxx/IncomingPhoneNumbers/PNxxxxxxxx.json
was not found
I have checked the account sids and number sids and they are correct.
Any idea where I'm going wrong here?
Here is my Try that happens in a foreach which credentials for every subaccount.
try
{
$client = new Client($sid, $token); //subaccount sid and token from not shown foreach
$caller_ids = $client->outgoingCallerIds->read();
foreach ($caller_ids as $caller_id)
{
$phone_number = $caller_id->phoneNumber;
$friendly_name = $caller_id->friendlyName;
$number_sid = $caller_id->sid;
$account_sid = $caller_id->accountSid;
$incoming_phone_number = $master_account->incomingPhoneNumbers("$number_sid")
->update(
array("accountSid" => "$account_sid")
);
}
}
Twilio developer evangelist here.
I believe the issue here is that you are using the master account sid to refer to the number that sits within the subaccount thus getting a 404. Instead you should select the subaccount from within the master account's list of accounts, and use that subaccount object to refer to the number as you transfer it.
For example:
$subaccount = $master_account->accounts($subaccount_sid);
$incoming_phone_number = $subaccount->incomingPhoneNumbers($number_sid)
->update(
array("accountSid" => $master_account->sid)
);
Let me know if this helps at all.
I'm creating an AI Assistant using Dialogflow and I need to use Google APIs (google calendar and gmail). The APIs were working perfectly (I used this as reference). However, when I integrated my code with the dialogflow webhook, it returns Webhook Call failed. Error: 500 Internal Server Error.
here is a code snippet:
$client = new Google_Client();
$client->addScope(Google_Service_Gmail::GMAIL_READONLY); //view your emails and settings
$client->addScope(Google_Service_Gmail::GMAIL_COMPOSE); //manage drafts and send emails
$client->addScope(Google_Service_Gmail::GMAIL_MODIFY);
$client->addScope(Google_Service_Gmail::GMAIL_SEND); //send email on your behalf
$client->addScope(Google_Service_Calendar::CALENDAR); //manage calendar
$client->setAuthConfig('client_secret.json');
$client->setAccessType('offline');
$client->setApprovalPrompt('auto');
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(isset($_SESSION['access_token']) && $_SESSION['access_token']){
$client->setAccessToken($_SESSION['access_token']);
$gmail = new Google_Service_Gmail($client);
$user = "emailaddress#gmail.com";
$calendar = new Google_Service_Calendar($client);
$intent = $json->queryResult->intent->displayName;
$location_any = $json->queryResult->parameters->location_any;
$text = $json->queryResult->parameters->text;
$name = $json->queryResult->parameters->name;
$choice = $json->queryResult->parameters->choice;
$subject = $json->queryResult->parameters->subject;
$location = $json->queryResult->parameters->location;
$description = $json->queryResult->parameters->description;
$startDateTime = $json->queryResult->parameters->startDateTime;
$endDateTime = $json->queryResult->parameters->endDateTime;
if($intent== "UnreadMessages"){
$unread = unReadMessages($gmail, $user);
$speech = "You have ".$unread." messages";
}
else if($intent == "GetSchedule"){
$events = get_event($calendar);
if($events){
$reply = "You have the following events coming up:";
foreach($events as $event){
$eventName = $event['eventName'];
$eventTime = $event['time'];
$reply .= $eventName."is at".$eventTime;
}
$speech = $reply;
}
else{
$speech = "You don't have any events coming up.";
}
}
}
I'm suspecting it may be because of the authentication process that's required everytime I try to run the app, since the error only starts popping up whenever I check for session tokens. My problem now is how do I remove this authentication process?
You have several serious issues with your approach here, but most of them result from you treating the interaction with the Google Assistant like it was a browser hitting your web page. Although Actions on Google uses HTTPS and a webhook, it is otherwise not really like a browser at all.
For example, you check $_SESSION to see if an access token has already been set. $_SESSION is typically implemented by setting a session ID in the browser with a session cookie. The Assistant doesn't use cookies at all. Although it has a userStorage object which can be used it similar ways, this is accessed very differently.
It isn't clear if this is what is causing the error, or if the problem is related here somewhere. If you do have error logs, this would be useful to include in the question.
There is a lot that remains unclear. Primarily - where does the auth token come from in the first place in your code.
In a purely web-based OAuth scheme, you'll direct the user to log in using Google Sign In and, as part of that process, request authorization to access their Drive and GMail. Google Sign In for the Assistant doesn't allow you to do that - all it gives you is an Identity Token.
You can use Account Linking to link the Assistant account to your system - but this requires you to have an OAuth server that generates the auth token that the Assistant will give back to you. This is your OAuth token - not one that comes from Google (unless you're proxying it).
If you have a web-based way to get authorization, you can leverage this to provide access through the Assistant as well using Google Sign In for the Assistant.
I created one service account with role big query admin.I am Using big query PHP API. Let me know if any other permission is required or not?
It gives me an error stating that the:
service account does not have bigquery.jobs.create permission.
I wanted to run a query on bigquery. Please help.
Following is my code:
$service = new Google_Service_Bigquery($client);
$query = new Google_Service_Bigquery_QueryRequest($client);
$query->setQuery('SELECT * FROM [xxx:xxx.xxs] LIMIT 1000;');
$jobs = $service->jobs;
$response = $jobs->query($project_id, $query);
// Do something with the BigQuery API $response data
print_r($response)
;
I ran into this problem using the BQ library for nodejs.
It seems being signed into a user/service account via the CLI is not always enough. My service account was authenticated and had the correct permissions in the GCP SDK Shell, but I still got service account does not have bigquery.jobs.create permission..
I was able to fix this by simply adding the same service account details, using the client library methods. I used https://googleapis.dev/nodejs/bigquery/latest/BigQuery.html.
In the case of nodejs, I just had to add
// Imports BigQuery library
const {BigQuery} = require('#google-cloud/bigquery');
// Create BQ Options - this object is what fixed the issue
const bqOptions = {};
bqOptions.projectId = '*your-project-name*';
bqOptions.keyFilename = '*Path-to-service-account-private-key*';
// Creates BQ client
const bq = new BigQuery(bqOptions);
I know you are using the PHP library, but I think the PHP equivalent would work the same.
I need to insert user's email in postBody of mirror API insert method. I am using this code:
$authtoken=null;
$postBody = new Google_Service_Mirror_Account();
$postBody->setAuthTokens($authtoken);
$userdata=array("email"=>$email);
$postBody->setUserData($userdata);
$account = $service->accounts->insert($userToken, package-name-here, $accountName, $postBody);
The above method returns null in response! I am not sure what to add as authtoken.
After this, I need to retrieve user's email account through Android's account manager:
AccountManager manager = AccountManager.get(c);
Account[] list = manager.getAccountsByType(package-name-here);
for (Account acct : list) {
accountEmailId= manager.getUserData(acct, "email");
break;
}
This doesn't seem to work. I do not get accounts of this type in Glass device. Any help will be great.
EDIT:
Added the authTokenArray and userDataArray to postBody as suggested below:
$userDataArray= array();
$userData1= new Google_Service_Mirror_UserData();
$userData1->setKey('email');
$userData1->setValue($email);
$userDataArray[]=$userData1;
$authTokenArray= array();
$authToken1= new Google_Service_Mirror_AuthToken();
$authToken1->setAuthToken('randomtoken');
$authToken1->setType('randomType');
$authTokenArray[]=$authToken1;
$postBody = new Google_Service_Mirror_Account();
$postBody->setUserData($userDataArray);
$postBody->setAuthTokens($authTokenArray);
Account insert method still returns null. Unable to solve the issue till now.
[SOLVED]
Mirror API still returns NULL response, but account is actually being inserted in Mirror API. Updated code can be viewed here: http://goo.gl/DVggO6
setAuthTokens takes an array of Google_Service_Mirror_AuthToken objects (see the source here), each of which has an authToken (an arbitrary string of your choosing) and a type (another arbitrary string). These values are copied directly into the account in the Android AccountManager so that you can look them on the device.
Your problem might be coming from the fact that you're passing in null for that right now. I would try fixing that and then see if you're able to see the account on the device.