I am trying to make request to OneDrive, but so far no success. I have been able to obtain access token that I think is good because I can access informations from https://graph.microsoft.com/v1.0/me. But when I try to access https://graph.microsoft.com/v1.0/me/drive I get 500 error response, this is what response object says:
[message:protected] => Unable to resolve template token
[string:Exception:private] =>
[code:protected] => 500
[file:protected] => C:\xampp\htdocs\OneDrive\vendor\thenetworg\oauth2-azure\src\Provider\Azure.php
[line:protected] => 68
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => C:\xampp\htdocs\OneDrive\vendor\league\oauth2-client\src\Provider\AbstractProvider.php
[line] => 644
[function] => checkResponse
[class] => TheNetworg\OAuth2\Client\Provider\Azure
[type] => ->
[args] => Array
(
[0] => GuzzleHttp\Psr7\Response Object
(
[reasonPhrase:GuzzleHttp\Psr7\Response:private] => Internal Server Error
[statusCode:GuzzleHttp\Psr7\Response:private] => 500
[headers:GuzzleHttp\Psr7\Response:private] => Array
(
[Cache-Control] => Array
(
[0] => private
)
[Transfer-Encoding] => Array
(
[0] => chunked
)
[Content-Type] => Array
(
[0] => application/json
)
[request-id] => Array
(
[0] => 7fc5c1c8-bd33-4788-bae9-5887d261c8c5
)
[client-request-id] => Array
(
[0] => 7fc5c1c8-bd33-4788-bae9-5887d261c8c5
)
[x-ms-ags-diagnostic] => Array
(
[0] => {"ServerInfo":{"DataCenter":"West Europe","Slice":"SliceB","ScaleUnit":"003","Host":"AGSFE_IN_2","ADSiteName":"AMS"}}
)
[Duration] => Array
(
[0] => 177.0851
)
[Date] => Array
(
[0] => Mon, 06 Feb 2017 12:55:27 GMT
)
)
[headerNames:GuzzleHttp\Psr7\Response:private] => Array
(
[cache-control] => Cache-Control
[transfer-encoding] => Transfer-Encoding
[content-type] => Content-Type
[request-id] => request-id
[client-request-id] => client-request-id
[x-ms-ags-diagnostic] => x-ms-ags-diagnostic
[duration] => Duration
[date] => Date
)
[protocol:GuzzleHttp\Psr7\Response:private] => 1.1
[stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #79
[size:GuzzleHttp\Psr7\Stream:private] => 237
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
)
[1] => Array
(
[error] => Array
(
[code] => InternalServerError
[message] => Unable to resolve template token
[innerError] => Array
(
[request-id] => 7fc5c1c8-bd33-4788-bae9-5887d261c8c5
[date] => 2017-02-06T12:55:28
)
)
)
)
)
Problem was that I was using thephpleague/oauth2 package that is recommended by official docs. Links to token and authorize URL were not to the v2.0 endpoint.
I am trying to get response from
https://graph.microsoft.com/v1.0/me/drive
but so far all I am getting is exception
Uncaught exception 'League\OAuth2\Client\Provider\Exception\IdentityProviderException' with message 'Unable to resolve template token'
I am using this Azure Active Directory oauth2 library that was recommended in documentation.
After obtaining access token I try to call
$this->provider->get('https://graph.microsoft.com/v1.0/me/drive',$_SESSION['access_token']); but that only throw exception. If I use
$this->provider->get('https://graph.microsoft.com/v1.0/me',$_SESSION['access_token']);
It returns informations about user account.
This is the error message that I am getting.
[message:protected] => Unable to resolve template token
[string:Exception:private] =>
[code:protected] => 500
[file:protected] => C:\xampp\htdocs\OneDrive\vendor\thenetworg\oauth2-azure\src\Provider\Azure.php
[line:protected] => 68
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => C:\xampp\htdocs\OneDrive\vendor\league\oauth2-client\src\Provider\AbstractProvider.php
[line] => 644
[function] => checkResponse
[class] => TheNetworg\OAuth2\Client\Provider\Azure
[type] => ->
[args] => Array
(
[0] => GuzzleHttp\Psr7\Response Object
(
[reasonPhrase:GuzzleHttp\Psr7\Response:private] => Internal Server Error
[statusCode:GuzzleHttp\Psr7\Response:private] => 500
[headers:GuzzleHttp\Psr7\Response:private] => Array
(
[Cache-Control] => Array
(
[0] => private
)
[Transfer-Encoding] => Array
(
[0] => chunked
)
[Content-Type] => Array
(
[0] => application/json
)
[request-id] => Array
(
[0] => 7fc5c1c8-bd33-4788-bae9-5887d261c8c5
)
[client-request-id] => Array
(
[0] => 7fc5c1c8-bd33-4788-bae9-5887d261c8c5
)
[x-ms-ags-diagnostic] => Array
(
[0] => {"ServerInfo":{"DataCenter":"West Europe","Slice":"SliceB","ScaleUnit":"003","Host":"AGSFE_IN_2","ADSiteName":"AMS"}}
)
[Duration] => Array
(
[0] => 177.0851
)
[Date] => Array
(
[0] => Mon, 06 Feb 2017 12:55:27 GMT
)
)
[headerNames:GuzzleHttp\Psr7\Response:private] => Array
(
[cache-control] => Cache-Control
[transfer-encoding] => Transfer-Encoding
[content-type] => Content-Type
[request-id] => request-id
[client-request-id] => client-request-id
[x-ms-ags-diagnostic] => x-ms-ags-diagnostic
[duration] => Duration
[date] => Date
)
[protocol:GuzzleHttp\Psr7\Response:private] => 1.1
[stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #79
[size:GuzzleHttp\Psr7\Stream:private] => 237
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
)
[1] => Array
(
[error] => Array
(
[code] => InternalServerError
[message] => Unable to resolve template token
[innerError] => Array
(
[request-id] => 7fc5c1c8-bd33-4788-bae9-5887d261c8c5
[date] => 2017-02-06T12:55:28
)
)
)
)
)
So it returns status code 500 which probably means that error is on their side. But If I try to access https://graph.microsoft.com/v1.0/me/drive through https://graph.microsoft.io/en-us/graph-explorer then I get normal response.
Also one thing I noticed is that I cannot change permission of access token. I tried to change it in Application registration portal, and also in my code I set scopes, but my token has always same permission [scope] => Files.ReadWrite User.Read
EDIT:
Here is what my request object looks like
GuzzleHttp\Psr7\Request Object
(
[method:GuzzleHttp\Psr7\Request:private] => GET
[requestTarget:GuzzleHttp\Psr7\Request:private] =>
[uri:GuzzleHttp\Psr7\Request:private] => GuzzleHttp\Psr7\Uri Object
(
[scheme:GuzzleHttp\Psr7\Uri:private] => https
[userInfo:GuzzleHttp\Psr7\Uri:private] =>
[host:GuzzleHttp\Psr7\Uri:private] => graph.microsoft.com
[port:GuzzleHttp\Psr7\Uri:private] =>
[path:GuzzleHttp\Psr7\Uri:private] => /v1.0/me/drive
[query:GuzzleHttp\Psr7\Uri:private] =>
[fragment:GuzzleHttp\Psr7\Uri:private] =>
)
[headers:GuzzleHttp\Psr7\Request:private] => Array
(
[Host] => Array
(
[0] => graph.microsoft.com
)
[Authorization] => Array
(
[0] => Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6IkFRQUJBQUFBQUFEUk5ZUlEzZGhSU3JtLTRLLWFkcENKbFFSTFVXOUFERTZ0X0FwV0JuMGZNSTFUbC1Mb3ZFanBSaURnNU5laEFMTVgzbkU3U18xRkNWc2pwM19scEZoekNUSTZLbnkxN01ybFg0RGpRNHVwQUNBQSIsImFsZyI6IlJTMjU2IiwieDV0IjoiWTR1ZUsyb2FJTlFpUWI1WUVCU1lWeURjcEFVIiwia2lkIjoiWTR1ZUsyb2FJTlFpUWI1WUVCU1lWeURjcEFVIn0.eyJhdWQiOiJodHRwczovL2dyYXBoLm1pY3Jvc29mdC5jb20vIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvOTE4ODA0MGQtNmM2Ny00YzViLWIxMTItMzZhMzA0YjY2ZGFkLyIsImlhdCI6MTQ4NjQ1ODk1MiwibmJmIjoxNDg2NDU4OTUyLCJleHAiOjE0ODY0NjI4NTIsImFjciI6IjEiLCJhaW8iOiJBUUFCQUFFQUFBRFJOWVJRM2RoUlNybS00Sy1hZHBDSmxsbjlqVi11Wl9qOVlwYUltZ04zbEZ3cEUxUlp5QkNJelh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Esles3uGi2QEkila1P73hPGAuCORkwPEMolLQwr33G1KSAZpB0OnvhTfghNt82_abpFiq14b5QXvrDgEQvtTtAqVZke-kOwOGTy4FJ9y50ZQ0rij9StRBq1CvVCJlcEcUZay5dRYfrLrdt8Wr-NLt1NGVayxWQ8Zlp68o7RXZ1nrGWAyLJ9ReQsP0ToCzJU2RP8n9U_batLSqew
)
)
[headerNames:GuzzleHttp\Psr7\Request:private] => Array
(
[authorization] => Authorization
[host] => Host
)
[protocol:GuzzleHttp\Psr7\Request:private] => 1.1
[stream:GuzzleHttp\Psr7\Request:private] =>
)
The token needs to be supplied in the request header via the Authorization property. Note that you must prepend "Bearer " to the token in the header.
Authorization: Bearer <token>
Update:
If you've change the scopes defined in Active Directory, you will also need to have the user re-consent to the new scopes. To force this, include prompt=consent in your query string.
Dear Brantree Developer(s) , I am trying to implement the braintree payments in my website and braintree has given Response in object of array with nested object How can i access it?. i want to get id of customer from bellow response.
Braintree_Result_Successful Object
(
[success] => 1
[_returnObjectNames:private] => Array
(
[0] => customer
)
[_attributes] => Array
(
)
[customer] => Braintree_Customer Object
(
[_attributes:protected] => Array
(
[id] => 22635830
[merchantId] => h9xhpt9b5zjgbkpj
[firstName] => Abhishek
[lastName] => Sonawane
[company] => 1
[email] => abhishek#iarianatech.com
[phone] =>
[fax] =>
[website] =>
[createdAt] => DateTime Object
(
)
[updatedAt] => DateTime Object
(
)
[customFields] =>
[creditCards] => Array
(
[0] => Braintree_CreditCard Object
(
[_attributes] => Array
(
[bin] => 510510
[expirationMonth] => 12
[expirationYear] => 2015
[last4] => 5100
[cardType] => MasterCard
[cardholderName] =>
[commercial] => Unknown
[countryOfIssuance] => Unknown
[createdAt] => DateTime Object
(
)
[customerId] => 22635830
[customerLocation] => US
[debit] => Unknown
[default] => 1
[durbinRegulated] => Unknown
[expired] =>
[healthcare] => Unknown
[imageUrl] => https://assets.braintreegateway.com/payment_method_logo/mastercard.png?environment=sandbox
[issuingBank] => Unknown
[payroll] => Unknown
[prepaid] => Unknown
[subscriptions] => Array
(
)
[token] => 6k2mk2
[uniqueNumberIdentifier] => 0ec6bdfe18781d1bccaea74c4fe55897
[updatedAt] => DateTime Object
(
)
[venmoSdk] =>
[verifications] => Array
(
)
[billingAddress] =>
[expirationDate] => 12/2015
[maskedNumber] => 510510******5100
)
)
)
[addresses] => Array
(
)
[coinbaseAccounts] => Array
(
)
[paypalAccounts] => Array
(
)
[applePayCards] => Array
(
)
)
)
)
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
It looks like that response is coming from a Customer create call. To specifically retrieve the id -
$result = Braintree_Customer::create([
'firstName' => 'Mike',
'lastName' => 'Jones',
'company' => 'Jones Co.',
'email' => 'mike.jones#example.com',
'phone' => '281.330.8004',
'fax' => '419.555.1235',
'website' => 'http://example.com'
]);
$result->success;
# true
$id = $result->customer->id;
Check the API Response section of the guides for getting other attributes.
I get list Metadata for different SharepointLists from calling the Lists-Webservice:
[DocTemplateUrl] =>
[DefaultViewUrl] =>
[MobileDefaultViewUrl] =>
[ID] => {D33D2DEF-1404-4007-8D79-EE9EF75E5AC4}
[Title] => appdata
[Description] =>
[ImageUrl] => /_layouts/15/images/itgen.png?rev=23
[Name] => {D33D2DEF-1404-4007-8D79-EE9EF75E5AC4}
[BaseType] => 0
[FeatureId] =>
[ServerTemplate] => 125
[Created] => 20141006 14:46:58
[Modified] => 20141006 14:46:58
[LastDeleted] => 20141006 14:46:58
[Version] => 0
[Direction] => none
[ThumbnailSize] =>
[WebImageWidth] =>
[WebImageHeight] =>
[Flags] => 20756
[ItemCount] => 0
[AnonymousPermMask] => 0
[RootFolder] =>
[ReadSecurity] => 1
[WriteSecurity] => 1
[Author] => 3
[EventSinkAssembly] =>
[EventSinkClass] =>
[EventSinkData] =>
[EmailAlias] =>
[WebFullUrl] => /
[WebId] => 1f8e1fa6-d3fa-4393-98f5-deb4b3c89040
[SendToLocation] =>
[ScopeId] => 5c1f32b6-cb59-4ac8-b5ba-4eac5788c671
[MajorVersionLimit] => 0
[MajorWithMinorVersionsLimit] => 0
[WorkFlowId] =>
[HasUniqueScopes] => False
[NoThrottleListOperations] => False
[HasRelatedLists] =>
[Followable] => False
[AllowDeletion] => False
[AllowMultiResponses] => False
[EnableAttachments] => True
[EnableModeration] => False
[EnableVersioning] => False
[HasExternalDataSource] => False
[Hidden] => True
[MultipleDataList] => False
[Ordered] => False
[ShowUser] => True
[EnablePeopleSelector] => False
[EnableResourceSelector] => False
[EnableMinorVersion] => False
[RequireCheckout] => False
[ThrottleListOperations] => False
[ExcludeFromOfflineClient] => False
[CanOpenFileAsync] => True
[EnableFolderCreation] => True
[IrmEnabled] => False
[IsApplicationList] => False
[PreserveEmptyValues] => False
[StrictTypeCoercion] => False
[EnforceDataValidation] => False
[MaxItemsPerThrottledOperation] => 5000
Is it possible to add a new field to a list in Sharepoint? I don't want to add a column for the document attributes in a list, but add a field as a list metadata to retrieve it with the lists-webservice.
THX!
You can add existing site column, create a new site column, create a new list column and so on. Just pick your preference, in any normal case your would like to create a site column.
This can be done either by code, powershell or the SharePoint gui
PowerShell, http://adicodes.com/add-fields-to-list-with-powershell-in-sharepoint-2010/
Gui, https://www.youtube.com/watch?v=rvPDZ598Xxk
Code, http://msdn.microsoft.com/en-us/library/office/ms437580(v=office.15).aspx
But since you are asking this I suggest you keep to the GUI until you learn a bit more on SharePoint
What I'm trying to accomplish
I'm building a favorites module and I need the ability to:
Select from a dropdown, hardcoded list of options
Have it save to the database
Upon refreshing the page, remove the already saved option from the list of options so it may not be added again
The third part is where I am unsure of how to proceed.
How my code is set up
This is my form:
/*
* Implentation of hook_form().
*/
function f25_favorites_form() {
$listOfPaths = f25_favorites_listOfPaths();
$form['path_options'] = array(
'#type' => 'value',
'#value' => array(
'default' => $listOfPaths['default']['#title'],
'concierge' => $listOfPaths['concierge']['#title'],
'concierge/add' => $listOfPaths['concierge/add']['#title'],
'survey-questions' => $listOfPaths['survey-questions']['#title'],
'survey-questions/add' => $listOfPaths['survey-questions/add']['#title'],
'profiles' => $listOfPaths['profiles']['#title'],
'profiles/add' => $listOfPaths['profiles/add']['#title'],
'statistics' => $listOfPaths['statistics']['#title'],
)
);
$form['path'] = array(
'#type' => 'select',
'#title' => t('Select Page'),
'#required' => TRUE,
'#weight' => '11',
'#options' => $form['path_options']['#value'],
);
$form[submit] = array(
'#type' => 'submit',
'#weight' => '1000000',
'#value' => t('Add')
);
return $form;
}
The name of the paths/options are called via a reference array:
/*
* List of Paths to add to favorites
*/
function f25_favorites_listOfPaths() {
$list = array();
$list = array(
'default' => array(
'#title' => t('Add to favorites'),
),
'concierge' => array(
'#title' => t('Concierge'),
'#image' => drupal_get_path('module', 'f25_favorites').'/img/concierge.png',
'#desc' => t('Concierge'),
),
'concierge/add' => array(
'#title' => t('New Concierge'),
'#image' => drupal_get_path('module', 'f25_favorites').'/img/concierge.png',
'#desc' => t('Concierge > Add'),
),
'survey-questions' => array(
'#title' => t('Survey Questions'),
'#image' => drupal_get_path('module', 'f25_favorites').'/img/survey-questions.png',
'#desc' => t('Current Survey Questions'),
),
'survey-questions/add' => array(
'#title' => t('New Survey Question'),
'#image' => drupal_get_path('module', 'f25_favorites').'/img/survey-questions.png',
'#desc' => t('Survery Question > Add'),
),
'profiles' => array(
'#title' => t('Profiles'),
'#image' => drupal_get_path('module', 'f25_favorites').'/img/profiles.png',
'#desc' => t('User Profiles'),
),
'profiles/add' => array(
'#title' => t('Add Profile'),
'#image' => drupal_get_path('module', 'f25_favorites').'/img/profiles.png',
'#desc' => t('Profiles > Add'),
),
'statistics' => array(
'#title' => t('Statistics'),
'#image' => drupal_get_path('module', 'f25_favorites').'/img/statistics.png',
'#desc' => t('Performance Stats'),
),
);
return $list;
}
And all this is what grabs the data on the databse:
/*
* Write Form data to database
*/
function f25_favorites_form_submit($form, &$form_state){
global $user;
$listOfPaths = f25_favorites_listOfPaths();
$selected = $form_state['values']['path'];
$data = array(
'uid' => $user->uid,
'path' => $selected,
'title' => $listOfPaths[$selected]['#title'],
'weight' => 10,
'timestamp' => time(),
);
drupal_write_record(f25_favorites, $data);
}
Possible Solutions
I've been told that I could used hook_form_alter() in order to modify my array but I am unsure as to when I should be comparing the db_query to my array and how to modify the differences accordingly.
I hope I've done a good job explaining what I'm try to do.
What would be the best way to accomplish this?
Instead of writing every response in f25_favorites_listOfPaths(), shouldn't you get them from the database?
You can then change whatever you want in the submit function to the database so that you don't fetch again the previously selected answer.
Example :
function f25_favorites_listOfPaths() {
return variable_get('f25_favorites_array_' . $user->uid, array(
// your $list array
));
}
function f25_favorites_submit_form($form, &$form_state) {
// your stuff already
drupal_write_record(f25_favorites, $data);
// Now what I propose you to do :)
variable_set('f25_favorites_array_' . $user->uid, array(
// new $list array without the favorite selected
));
}
The use of variable_get/set() should of course be replaced by your own table if you have too much datas.
P.S. : hook_form() does not exist :)