Oauth2 Data from Google after authorization - php

While learning about Google Oauth2, I saw two options for implementation
Option 1) Using PHP client library installed locally on server
example - http://phppot.com/php/php-google-oauth-login/
Option2) Using Javascript, AJAX, PHP & the google platform library (from CDN directly)
example - http://w3lessons.info/2015/05/19/google-oauth-2-0-ajax-login-using-jquery-php-mysql/
I have been able to implement both. However I have following questions:
Question 1)
In option 1 [$profile = $this->client->verifyIdToken()->getAttributes();] gives me profile data which contains only email[email] & google ID[sub].
Output: of $profile
Array
(
[envelope] => Array
(
[alg] => R256
[kid] => ca6f0ece055ffa823454e56da
)
[payload] => Array
(
[iss] => accounts.google.com
[at_hash] => e5l-tvQpWQ
[aud] => 8pps.googleusercontent.com
[sub] => 186524872
[email_verified] => 1
[azp] => 1go.apps.googleusercontent.com
[email] => sagl#gmail.com
[iat] => 14543
[exp] => 14543
)
)
In option 2 [var profile = googleUser.getBasicProfile();] gives me a profile data which contains the full name & the profile picture link on top of google ID & email
Is there any function which can get me the Profile name & picture link using option 1 (only PHP based implementation)
Question 2) For option 2 how can I modify the default "Google button" logo being sent by Google through the div:
<div class="g-signin2" data-longtitle="true" data-onsuccess="Google_signIn" data-theme="light" data-width="200"/>

Question 1: $profile['payload'] now has an additional key named picture and its value is a URL to the profile picture.
Question 2: There are a limited number of attributes you can use to customize your sign-in button: data-scope, width, height, data-longtitle, data-theme, data-onsuccess, and data-onfailure. data-scope is used to request permission scopes. data-longtitle takes a true or false(default) value to determine whether you want to display "sign in with google" or "sign in", respectively. data-theme takes values light or dark. And data-onsuccess and data-onfailure take js functions to be called on successful/failed sign in attempts.
Beyond that, you'll have to do some reading to really customize the button here: https://developers.google.com/identity/sign-in/web/build-button#customizing_the_automatically_rendered_sign-in_button_recommended

Related

how to display specific account records in popup in suitecrm

I've created one 'account_category' field in account module. It is dropdown and have following options:
principle
customer
supplier
manufacturer
I created Account relationship with Opportunity module.
In the Account popup i want to display only those records which have account_category as principle.
My file path : custom/modules/opportunity/metadata/editviewdef.php
1 =>
array (
'name' => 'opportunities_accounts_1_name',
'displayParams' =>
array (
'initial_filter' => '&account_category_c="Principle"',
),
),
But it is not working..
Please help to filter accounts on the basis of account_category_c as principle
Add the word _advanced like this:
'initial_filter' => '&account_category_c_advanced="Principle"',
see:
http://academe.co.uk/2013/03/sugarcrm-relate-field-passing-default-values-to-pop-up-select-form/
http://developer.sugarcrm.com/2011/08/31/howto-using-a-relate-field-to-populate-a-custom-field/

Google Calendar API always Paginates Event List

Summary:
Google_Service_Calendar seems to be "force-paginating" results of $service->events->listEvents();
Background:
google calendar API v3,
using php client library
We are developing a mechanism to sync our internal calendar with a user's google calendar.
Please note I will refer below to $x, which represents google's default limit on the number of events, similar to $options['maxResults']; The default value is 250, but it should not matter: we have tested the below with and without explicitly defined request parameters such as 'maxResults', 'timeMin', and 'timeMax' - the problem occurs in all cases.
Another relevant test we did: export this calendar to foobar.ics, created a new gmail user form scratch, import foobar.ics to newuser#gmail.com. DOES NOT REPLICATE THIS ISSUE. We have reviewed/reset various options in the subject calendar (sharing, etc) but cannot find any setting that has any effect.
The Problem:
Normally, when we call this:
$calendar='primary';
$optParams=array();
$events = $this->service->events->listEvents($calendar, $optParams);
$events comes back as a Google_Service_Calendar_Events object, containing $n "items". IF there are more than $x items, the results could be paginated, but the vanilla response (for a 'normal', result set with ( count($items) < $x ) ) is a single object, and $events->nextPageToken should be empty.
One account we are working with (of course, the boss's personal account) does not behave this way. The result of:
$events = $this->service->events->listEvents('primary', []);
is a Google_Service_Calendar_Events object like this:
Google_Service_Calendar_Events Object
(
[accessRole] => owner
[defaultRemindersType:protected] => Google_Service_Calendar_EventReminder
[defaultRemindersDataType:protected] => array
[description] =>
[etag] => "-kakMffdIzB99fTAlD9HooLp8eo/WiDS9OZS7i25CVZYoK2ZLLwG7bM"
[itemsType:protected] => Google_Service_Calendar_Event
[itemsDataType:protected] => array
[kind] => calendar#events
[nextPageToken] => CigKGmw5dGh1Mms4aWliMDNhanRvcWFzY3Y1ZGkwGAEggICA6-L3lrgUGg0IABIAGLig_Zfi278C
[nextSyncToken] =>
[summary] => example#mydomain.com
[timeZone] => America/New_York
[updated] => 2014-07-23T15:38:50.195Z
[collection_key:protected] => items
[modelData:protected] => Array
(
[defaultReminders] => Array
(
[0] => Array
(
[method] => popup
[minutes] => 30
)
)
[items] => Array
(
)
)
[processed:protected] => Array
(
)
)
Notice that $event['items'] is empty, and nextPageToken is not null. If we then do a paginated request like this:
while (true) {
$pageToken = $events->getNextPageToken();
if ($pageToken) {
$optParams = array('pageToken' => $pageToken);
$events = $this->service->events->listEvents($calendar, $optParams);
if(count($events) > 0){
h2("Google Service returned total of ".count($events)." events.");
}
} else {
break;
}
}
The next result set gives us the events. In other words, the google service seems to be paginating the initial results, despite the fact that we are certain the result is less than $x.
To be clear, if we have 5 events on our calendar, we expect 1 result with 5 items. Instead, we get 1 result with 0 items, but the first result of the 'nextPageToken' logic gives us the desired 5 items.
Solution Ideas?:
A. handle paginated results, and/or "Incremental Syncronization'. These are on our list of features to implement, but we consider these to be more 'optimization' than 'necessity'. In other words, I understand that handling/sending nextSyncToken and nextPageToken are OPTIONAL- thus the issue we are having should not depend on our client code doing this.
B. use a different, non-primary calendar for this user. we think this particular primary calendar may corrupt or somehow cached on google's side: to be fair, we did at one point accidentally insert a bunch of junk events on this calendar to the point that google put us in read-only mode as described here: https://support.google.com/a/answer/2905486?hl=en but we understand that was a temporary result of clunky testing.... In other words, we know we HAD screwed this calendar up badly, but this morning we deleted ALL events, added a single test event, and got the same result as above FOR THIS CALENDAR. Cannot replicate for any other user.... including a brand new gmail user.
C. delete the 'primary' calendar, create a new one. Unfortunately, we understand it is not possible to delete the primary CALENDAR, only to delete the CALENDAR EVENTS.
D. make the boss open a brand new google account
Any other suggestions? We are proceeding with A, but even that is a band-aid to the problem, and does not answer WHY is this happening? How can we avoid it in the future? (Please don't say "D")
Thanks in advance for any advice or input!
There is a maximum page size, if you don't specify one yourself there is an implicit one (https://developers.google.com/google-apps/calendar/v3/pagination). Given this it's necessary to implement pagination for your app to work correctly.
As you noticed, a page does not always contain the maximum number of results so pagination is important even if the number of events does not exceed the page size. Just keep following the page tokens and it will eventually give you all the results (there will be a page with no nextPageToken)
TL;DR A :)

SoundCloud - Update Cover / Artwork Image

We use the SoundCloud API to upload tracks with PHP. This is all working perfectly, but we would like to be able to update the track cover artwork with the SoundCloud API. We already upload the cover art when we initially upload the track, but when we try and modify it after the initial upload, it doesn't seem to work (we don't get any errors, it just doesn't get updated and stays the same as it was before).
Is this an intentional limitation of the SoundCloud API or am I missing something?
Edit 1:
I've emailed the SoundCloud API team to ask if they'd just clarify if updating track artwork is possible via the API, but I've had no response (around 48 hours so far).
Edit 2 - 2014-07-08:
4 days on and still no reply yet from the SoundCloud API team? Am I being ignorant thinking this is a simple "yes it should work" or "no that isn't supported with the current API" reply?
Edit 3 - 2014-08-28:
Over 7 weeks and still haven't heard anything from SoundCloud. Looks like they aren't going to be replying!
$track_info_array = array(
'track[title]' => $track['title'],
'track[sharing]' => $track['sharing'],
'track[track_type]' => $track['track_type'],
'track[purchase_url]' => $track['purchase_url'],
'track[description]' => $track['description'],
'track[genre]' => $track['genre'],
'track[label_name]' => $track['label_name'],
'track[tag_list]' => $track['tag_list'],
'track[release_day]' => $release_date[2],
'track[release_month]' => $release_date[1],
'track[release_year]' => $release_date[0],
'track[isrc]' => $track['isrc'],
'track[release]' => $track['release'],
'track[bpm]' => $track['bpm'],
'track[key_signature]' => $track['key_signature']
);
if($release_image){
$track_info_array['track[artwork_data]'] = '#'.$release_image;
}
$track_info = $soundcloud->put('tracks/' . $track['soundcloud_track_id'], $track_info_array);
If it's possible, I believe you want to use PUT instead of a POST request. you also will want to include the track's ID in the endpoint.
Acording to the docs, it is only possible to use artwork_data for uploading, no updates to the audio file nor the artwork.
The fields artwork_data and asset_data have a comment of "only for uploading"
Reference: https://developers.soundcloud.com/docs/api/reference#tracks
Delete all your temporary internet and cache files. It may actually be changing for everyone else but you.
There is a trick that usually works. The Soundcloud API may have some sloppy coding. Try editing the entire URL link for the target file. That should work.

Convert code to POST

i have a script (php+html) full of forms and inputs, after the form is submited via post i can give the user a code (like was a GET form) q=test&t=3&u=9&q2=test&t2=3&u2=9&q3=test&t3=3&3u=9, then the user can put this code in a textarea for editing what he previously submitted
how to transform the code inputed in the textarea (q&t&u) to work like if it was submitted like a normal POST? like if i where using $_POST['q'], $_POST['u'] but from that code submitted (like foreach)?
Look into parse_str
$str = 'q=test&t=3&u=9&q2=test&t2=3&u2=9&q3=test&t3=3&3u=9';
parse_str($str, $data);
print_r($data);
/*
Array
(
[q] => test
[t] => 3
[u] => 9
[q2] => test
[t2] => 3
[u2] => 9
[q3] => test
[t3] => 3
[3u] => 9
)
*/
What I understand from your question is. that you want save form and later want to allow ur visitor to update these details. Best way to do is.
you can generate a code(password) keep it in database along with record and provide it to your visitor
visitor will enter that code(unique) to get his record and can update that.

500 - An error has occurred – DB function reports no errors when adding new article in Joomla

I have an article that I want to publish on my Joomla! site. Every time I click apply or save. I get error 500 - An error has occurred! DB function reports no errors. I have no idea why this error comes up, al I can think is that it's a server error.
I'm using TinyMCE to type articles together with Joomla! 1.5.11.
Updated: I turned on Maximum error reporting in Joomla! and in the article manager I tried to save the article and got these couple of errors. Please check screenshot
I tried adding
<?php
ini_set('error_reporting', E_ALL);
error_reporting(E_ALL);
ini_set('log_errors',TRUE);
ini_set('html_errors',TRUE);
ini_set('display_errors',true);
?>
at the top of the index.php pages for Joomla! but it does not show any errors. I checked the error logs on the server and also no errors come up.
I managed to publish the article via phpMyAdmin but then something else happens. I try to access to article from the front end, by clicking on the link to the article, but only a blank page comes up.
This is really weird, since the error log does not show any information. So I assume the error needs to be coming from Joomla!
This happens if I add a print_r($_POST) before if (!$row->check()) { on /administrator/components/com_content/controller.php (around line 693)
Array
(
[title] => Test.
[state] => 0
[alias] => test
[frontpage] => 0
[sectionid] => 10
[catid] => 44
[details] => Array
(
[created_by] => 62
[created_by_alias] =>
[access] => 0
[created] => 2008-10-25 13:31:21
[publish_up] => 2008-10-25 13:31:21
[publish_down] => Never
)
[params] => Array
(
[show_title] =>
[link_titles] =>
[show_intro] =>
[show_section] =>
[link_section] =>
[show_category] =>
[link_category] =>
[show_vote] =>
[show_author] => 1
[show_create_date] => 0
[show_modify_date] => 0
[show_pdf_icon] =>
[show_print_icon] =>
[show_email_icon] =>
[language] =>
[keyref] =>
[readmore] =>
)
[meta] => Array
(
[description] => Test.
[keywords] => Test
[robots] =>
[author] => Test
)
[id] => 58
[cid] => Array
(
[0] => 58
)
[version] => 30
[mask] => 0
[option] => com_content
[task] => apply
[ac1e0853fb1b3f41730c0d52de89dab7] => 1
)
I had a bounty on this question, but the problem is still not resolved? link text
Any help will be appreciated!!
Here is a link to the article (text file with the source I got from TinyMCE) Article
I read this other question and saw that you can't post the article since it's confidential. Is it in "plain english", does it have html? Could you provide some more information? Joomla has some plugins that "filter" a lot of content. If you try to write "iframe" or "script" tags in Joomla TinyMCE it's going to be filtered, this is Joomla's way of providing security.
Did you try to disable TinyMCE filters? Go to "Plugin Manager", "Editor - TinyMCE 2.0" and change "Code cleanup" options to test.
Looking at your POST array, it looks like the body text of your post isn't being sent. This would suggest it's a problem on the front end. Can you check the name of the HTML element where you are typing the body text? If you could edit and show us the relevant parts of the HTML form that would help too.
edit: ok, that article you linked to is almost 150,000 bytes, so it might be that it's choking on it. If this is a once-off article that you probably won't have to edit too much, I'd recommend putting in some dummy text and then going into your database using phpMyAdmin or something and editing the text in the jos_content table. The introtext and fulltext columns are defined as MEDIUMTEXT so they should be able to hold up to about 16MB without hassle.
If writing and/or editing articles of this size is something you'll be doing often (and hence, don't want to go into the DB each time), then perhaps you'll have to look at the maximum post size allowed.
This error could occur when you use Firefox.
Try to reproduce using IE.
Regards
Simply do the following task
"""you can ask to your hosting provider to disable the function suhosin in php.ini. When this function is enable, is not possible to save large posts."""".
Shailedner Ahuja
My Web Developer
http://www.mywebdeveloper.in
Your article text is too big . The table might not be finding space to save this big . I would like suggest you to use the LONGTEXT
datatype. Check if it works for you .

Categories