I have google drive picker on my html form. However, when I click the button I get the browser message that 'popup is blocked'.
I need for this work without the user having to allow it. Can you please have a look at my code let me know how change it so that will work without the user having to enable popups
Thanks
Here is the code..
<a id="auth-button" class="google-drive-btn" ng-model="resume" href="#" ng- click="onGoogleLoad()">Choose from Google Drive</a>
$scope.onGoogleLoad = function () {
var flag = false;
$http.post('/api/controllers/googledownload/getClientkey').
success(function (data, status, header, config) {
gapi.client.load('drive', 'v2', null);
gapi.load('auth', { 'callback': onAuthApiLoad });
gapi.load('picker','1');
function onAuthApiLoad() {
window.gapi.auth.authorize({
'client_id': data.clientID,
'immediate': flag,
'scope': ['https://www.googleapis.com/auth/drive']
}, handleAuthResult);
}
function handleAuthResult(authResult) {
if (authResult && !authResult.error) {
oauthToken = authResult.access_token;
createPicker();
}
else
{
flag = true;
onAuthApiLoad();
}
}
function createPicker() {
var picker = new google.picker.PickerBuilder()
.addView(new google.picker.DocsView())
.setOAuthToken(oauthToken)
.setCallback(pickerCallback)
.build();
picker.setVisible(true);
}
function pickerCallback(data) {
if (data.action == google.picker.Action.PICKED) {
$scope.showspinner = true;
var doc = data.docs[0];
var fileId = doc.id;
var request = gapi.client.drive.files.get({
'fileId': fileId
});
request.execute(function (resp) {
var token = gapi.auth.getToken();
var fileData = {
name: resp.title,
link: resp.downloadUrl,
accessToken: token.access_token,
tokenType: token.token_type,
mimeType: resp.mimeType
};
var jsondata = JSON.stringify({ FileData: fileData });
$http.post('/api/controllers/files/CloudDownload', { googleFileData: fileData}).
success(function (data, status, headers, config) {
onFileUploadSuccess(data);
}).
error(function (data, status, header, config) {
$scope.showspinner = false;
});
});
}
else if (data.action == google.picker.Action.CANCEL) {
$scope.showspinner = false;
}
}
}).
error(function (data, status, header, config) {
$scope.showspinner = false;
});
}