I'm trying to create a page where users within my NGO can login using their GSuite Account. Their group membership is going to determine which parts of the page they can see. When I was younger I used to write my scripts in php, I guess I'm super old school with that nowadays but it's the only thing I can do :D
To retrieve the group memberships I have the following code:
config:
require_once "GoogleAPI/vendor/autoload.php";
$gClient = new Google_Client();
(...)
$gClient->addScope("https://www.googleapis.com/auth/plus.login");
$gClient->addScope("https://www.googleapis.com/auth/userinfo.email");
$gClient->addScope("https://www.googleapis.com/auth/admin.directory.group.readonly");
$gClient->addScope("https://www.googleapis.com/auth/admin.directory.group");
$gClient->addScope("https://www.googleapis.com/auth/admin.directory.user");
callback-file:
$oAuth = new Google_Service_Oauth2($gClient);
$userData = $oAuth->userinfo_v2_me->get();
$gruppen = new Google_Service_Directory($gClient);
$optParams = array('userKey' => $userData['id']);
$retGruppen = $gruppen->groups->listGroups($optParams);
$userData returns me the all the data i want about the user. That works quite fine.
The problem is calling the method "listGroups". And I get quite a weird response.
With the account I'm regulary using it works without any problems. I created a test account though - and this account doesn't seem to work at all.
The developers console shows me that I get a code 403 but that's weird cause it still works with one account and it doesn't with the other.
Through various var_dumps i found out that
var_dump($gruppen->groups->listGroups($optParams));
works for all cases, while it doesn't work anymore in the test account's case as soon as i add the method "->listGroups($optParams)"- but in the regular accounts case it does
Related
I have created a method to update all email signatures in my company.
It works, the signature is automatically set on new emails but for replies/forwards there is no signature.
Is it possible to update the signature for reply/forward?
My code:
public function updateSignature(User $user, string $email, string $newSignature): SendAs
{
// Executes the request with the address of its own user
$this->client->setSubject($user->getPrimaryEmail());
$serviceSendAs = new SendAs();
$serviceSendAs->setDisplayName($user->getFullName());
$serviceSendAs->setSignature($newSignature);
$serviceGmail = new Gmail($this->client);
return $serviceGmail->users_settings_sendAs->update($user->getPrimaryEmail(), $email, $serviceSendAs);
}
Thank ;)
I was running into the same issue and just figured out what's going on. For some Gmail accounts, the signature was updating and assigning both the "Compose" and "Reply/Forward" settings correctly, but for others, it was creating a new signature and only updating the "Compose" setting.
What I found was if I deleted all saved signatures for the accounts that were not updating the "Reply/Forward" setting and then ran the script, the signatures got created and both the "Compose" and "Reply/Forward" settings were set. Subsequent runs of the script also reflected correctly.
This is likely a bug since the API documentation explicitly states it will only update the "Compose" setting, but a favorable bug for sure.
Hope this helps!
I'm a total noob at programming. I'm currently creating a website where a user can register.
What I want to happen is the following:
When the user registers, he/she will be added to my MailerLite subscriber list.
All the information will also be saved to my website's database.
I played around with the MailerLite documentation but I can't seem to get anything to work.
I installed all the libraries found here: https://github.com/mailerlite/mailerlite-api-php-v1#installation using composer then I created a php file with this code:
`
<?php
require_once 'vendor/autoload.php';
$ML_Subscribers = new MailerLite\Subscribers("*my API*");
$subscriber = array(
'email' => 'first#example.com',
'name' => 'First name'
);
$result = $ML_Subscribers->setId( *my GROUP ID* )->add($subscriber);
?>'
but it appears to do nothing, once I submit the form, it will load the php file that I created and shows nothing, I check my subscriber list in MailerLite and nothing is added.
Please check what does the script return - add var_dump($result); in the end of the file.
And MailerLite doesn't accept "#example.com" emails, so be sure to change this
I would like to create a campaign using Facebook API. I tried to run all available example without success.
First of all I created an App in order to have a APP_ID and a APP_SECRET.
I did all the procedure to add my Ad_account following the tutorial.
I downloaded all the SDK to facilitate Facebook API use like:
facebook-php-ads-sdk and run adgroup_creation.php and curl_log.php with my data, without success.
facebook-php-sdk-v4 I suppose it is less specific than the previous one.
Multi-Product Ads with the Facebook Marketing POST -> developers.facebook.com/ads/blog/post/2015/03/26/creating-multi-product-ads/
the developers reference -> developers.facebook.com/docs/reference/php/4.0.0
I used "Composer" to get all dependency.
In all this case I had problem to create a campaign using more or less this code:
$campaign = new \FacebookAds\Object\AdCampaign(null,"act_$ACCOUNT_ID");
$campaign->setData(array(
AdCampaignFields::NAME => 'My First Campaign',
AdCampaignFields::OBJECTIVE => AdObjectives::WEBSITE_CLICKS,
AdCampaignFields::STATUS => AdCampaign::STATUS_PAUSED ));
// PROBLEM is Here
$campaign->create();
Any help? How can I get a more useful error?
It's difficult to help without knowing the exact error. However, you could try this: before creating your campaign, initialize the API using:
Api::init(<your_app_id>, <your_ap_secret>, <your_token>);
(You need to load FacebookAds\Api to use this function).
I'm currently trying to get a custom component working to log a user into the backend given their username and password. I realize the inherent security problems this may present, but I would really like an answer to this problem I've been struggling with. Here is the code in my controller.php:
function execute() {
$credentials = array( 'username' => $this->username,
'password' => $this->password );
$options = array();
$options['group'] = 'Public Backend';
$options['autoregister'] = false;
$options['action'] = 'core.login.admin';
$app =& JFactory::getApplication('administrator');
$result = $app->login($credentials, $options);
echo $result;
}
All the documentation that I've read says that this should work (even though it is not exactly kosher to perform admin tasks--like logging into the backend--from a non-admin context). Any idea on what I'm not getting?
EDIT: I forgot to mention which Joomla version I'm using: 2.5.14
I think you need to pay attention to the Joomla authentication/login/authorization flow and user flow which are managed via user and authentication plugins. From what you say it sounds like you will still be using the Joomla user table, is that right? So in that case the Joomla user plugin should work.
Assuming that is true you want to make an authentication plugin. This plugin will be checked along with the joomla authentication plugin and any other authentication plugins you may have running (e.g. remember me/cookie login).
I don't totally understand what you are trying to do (and you haven't said what version of Joomla you are on, which makes a difference in this case), for example do you really want to login to the full back end or do you just want to show some screens the way the insert image plugin does? If on Joomla 3 you might want to look at the Google Summer of Code project for bringing some admin to the front end (called com_services for now). That student also has an http login plugin you could look at. https://github.com/Buddhima/Joomla-HttpLogin-plugin
I'm running in circle with this problem so I submit it here.
I have created a facebook fanpage and a website for my mother to promote her music. Since she is quite used to facebook I decided that instead of creating a whole backoffice, the website would simply display the fanpage's posts, photos and events. I do this with simple calls to
$data= $fb->api('/'.PAGE_ID.'/posts?fields=id');
for example (or 'notes', 'events'...). The problem is that I have to use a specific access token that I get from my own 'me/accounts/' permissions. From time to time (say every month) I have to go to the Graph API Explorer, get that token, and save it in the website config.
I'm wondering if I couldn't generate that access token server-side on my website, but I can't seem to make it happen. the facebook PHP SDK can't acces my api('/accounts') graph results unless I'm the authentified user (obviously), and a call to api(PAGE_ID.'?fields=access_token') only returns the page's ID.
What Am I doing wrong? can the facebook php sdk make api calls on my behalf (independently of users)?
More info : I created the fanpage, and a simple app called feed reader, with *manage_pages* permission. I'm the only user that authorized that app, and I don't want the user on the website to have to login (why should they? it's my fanpage, why would I need their *manage_page* permission?).
To be honest I kinda feel that public posts sould be public in the graph api too, but I'm sure there is a reason.
To be honest I kinda feel that public posts sould be public in the graph api too, but I'm sure there is a reason.
You can get to any users public posts like so:
Note: this assumes you are using the PHP SDK here http://developers.facebook.com/docs/reference/php/
$facebook = new Facebook(
array(
'appId' => 'fb_app_id',
'secret' => 'fb_secret',
)
);
$url = '/' . 'fb_username' . '/posts?fields=id,name,created_time,message,story,type&limit=10'; // you might need to screw with this some
$page = $facebook->api($url);
while(count($page['data']) > 0)
{
foreach($page['data'] as $fb_post)
{
// USE THEM DATAS
}
// Keep retrieving next pages until spent
$url_parts = parse_url($page['paging']['next']);
$url = '/' . 'fb_username' . '/posts?' . $url_parts['query'];
$page = $facebook->api($url);
}
this is an example from: https://github.com/fyaconiello/WP_Social_Network_Posts/ which pulls FB posts in and saves em as WP posts. It was written to answer a different question.