setUserStatus() gives error - hybridauth

I want to share on facebook wall using hybridauth. Social logins perfectly works but the problem is when i post some message on Facebook wall using setUserStatus() it gives error but this code perfectly works for Twitter. also i searched a lot for Google plus wall sharing but not found any tutorial. kindly also tell how to share on Google plus.
error:
Fatal error: Uncaught Hybridauth\Exception\HttpRequestFailedException: Signed API request has returned an error. HTTP error 403. Raw Provider API response: {"error":{"message":"(#200) Requires either publish_actions permission, or manage_pages and publish_pages as an admin with sufficient administrative permission","type":"OAuthException","code":200,"fbtrace_id":"CbU\/8WTnigM"}}. in C:\xampp\htdocs\testphase-wholesale\hybridauth\src\Adapter\AbstractAdapter.php:360 Stack trace: #0 C:\xampp\htdocs\testphase-wholesale\hybridauth\src\Adapter\OAuth2.php(682): Hybridauth\Adapter\AbstractAdapter->validateApiResponse('Signed API requ...') #1 C:\xampp\htdocs\testphase-wholesale\hybridauth\src\Provider\Facebook.php(235): Hybridauth\Adapter\OAuth2->apiRequest('https://graph.f...', 'POST', Array) #2 C:\xampp\htdocs\testphase-wholesale\example\home.php(126): Hybridauth\Provider\Facebook->setUserStatus(Array) #3 {main} thrown in C:\xampp\htdocs\testphase-wholesale\hybridauth\src\Adapter\AbstractAdapter.php on line 360
Note: working on Localhost. setUserStatus() works perfectly on Twitter.
if (isset($_POST['btn_post_message'])) {
$message = $_POST['message_text'];
// init hybridauth
$hybridauth = new Hybridauth($config);
// try to authenticate with twitter
$adapter = $hybridauth->authenticate($provider);
if($provider == 'Facebook') {
// update the user status or post to wall
$adapter->setUserStatus(
array(
"message" => $message, // status or message content
"link" => "sdf" // a picture link
));
} else{
// update the user status
$adapter->setUserStatus($message);
}
}
Config.php
<?php
/**
* Build a configuration array to pass to `Hybridauth\Hybridauth`
*/
$config = [
/**
* Set the Authorization callback URL to https://path/to/hybridauth/examples/example_06/callback.php.
* Understandably, you need to replace 'path/to/hybridauth' with the real path to this script.
*/
'callback' => 'http://localhost/testphase-wholesale/example/callback.php',
'providers' => [
'Twitter' => [
'enabled' => true,
'keys' => [
'key' => '...',
'secret' => '...',
],
],
'Google' => [
'enabled' => true,
'keys' => [
'id' => '',
'secret' => '',
],
"scope" => "https://www.googleapis.com/auth/plus.login ". // optional
"https://www.googleapis.com/auth/plus.me ". // optional
"https://www.googleapis.com/auth/plus.profile.emails.read", // optional
],
'Twitter' => [
'enabled' => true,
'keys' => [
'id' => '=',
'secret' => '',
],
"scope" => "email", // optional
],
'Facebook' => [
'enabled' => true,
"scope" => "email,user_gender, user_friends, user_birthday, user_age_range, user_hometown, user_link, user_location",
"trustForwarded" => false,
'keys' => [
'id' => '',
'secret' => '',
],
],
],
];

Related

Not enough permissions to access: POST /invitations

Unable to send invitation. Token is correct/non-expired.
Permissions:
r_ads
w_organization_social
rw_ads
r_basicprofile
r_ads_reporting
r_organization_social
rw_organization_admin
w_member_social
Added products:
Marketing Developer Platform
Share on LinkedIn
Code:
$client = new Client([
'base_uri' => 'https://api.linkedin.com/v2/',
'timeout' => 9.0,
]);
$headers = [
'Connection' => 'Keep-Alive',
'Authorization' => 'Bearer '.$myAccessToken,
];
$body = json_encode([
'invitee' => "urn:li:email:myEmail#test.com",
'message' => [
'com.linkedin.invitations.InvitationMessage' => [
'body' => 'Let\'s connect!'
],
],
]);
// Send an asynchronous request.
$request = new \GuzzleHttp\Psr7\Request('POST', 'invitations', $headers, $body);
$promise = $client->sendAsync($request)->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
$promise->wait();
I mostly just want to know who to contact in order to get the correct permissions. Customer service does not handle any dev-related issues.

How to send an email to the user when performing login in cakephp

I do not have any knowledge about cakephp mail so explain the solution briefly I mean what to do and how to do from the beginning.
From the cakephp official side I just used this "use Cake\Mailer\Email;" and then the mail function but a error message shows like as shown below
Could not send email: mail(): Failed to connect to mailserver at
quot;server.com" port 25, verify your "SMTP" and
quot;smtp_port" setting in php.ini or use ini_set()
MY users controller login function
public function login() {
$this->viewBuilder()->setLayout('');
if ($this->request->is('post')) {
$data = $this->request->getData();
$query = $this->Users->find()->where(['email' => $data['email'], 'password' => md5($data['password'])]);
if ($query->count()) {
$user = $query->first()->toArray();
$this->Auth->setUser($user);
//FOR MAIL START
ini_set('SMTP', "server.com");
ini_set('smtp_port', "25");
ini_set('sendmail_from', "restrange5#gmail.com");
$email = new Email('default');
$email->setFrom(['restrange5#gmail.com' => 'My Site'])
->setTo('ramakantasahoo835#gmail.com')
->setSubject('About')
->send('My message');
//FOR MAIL END
$this->Flash->success(_('Login Successfull'));
$this->redirect(['action' => 'dashboard']);
} else {
$this->Flash->error(__('Username/Password not found!!'));
return $this->redirect($this->referer());
}
}
}
How much I know as I have just changed in users controller only. What else I have do please suggest.
**Your cofiguration in app.php file is something like this **'
EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'email here',
'password' => 'password here',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
]

LinkedIn API Publish on network (S_412_PRECONDITION_FAILED=Invalid arguments)

When I try to publish a link on my own LinkedIn profile via the LinkedIn API, I get this error:
LinkedIn return error
Request Error: Invalid arguments: {S_412_PRECONDITION_FAILED=Invalid arguments}
My request:
$li = new LinkedIn([
'api_key' => env('LINKEDIN_KEY'),
'api_secret' => env('LINKEDIN_SECRET'),
'callback_url' => env('LINKEDIN_REDIRECT_URI')
]);
$li->setAccessToken('my_token');
return $li->post('/people/~/shares', [
'content' => [
'title' => 'This is an example of title',
'description' => 'This is a text with less 256 caracters.',
'submitted-url' => 'https://www.google.fr/',
],
'comment' => 'This is comment with less 700 caracters.',
'visibility' => [
'code' => 'anyone'
]
]);
I use the official API of LinkedIn (linkedinapi/linkedin).

Send serialize data on kartik file input

I am implementing \kartik\file\FileInput widget.
Here is my code:
<?php
echo FileInput::widget([
'name' => 'dataSiswa',
'options' => [
'multiple' => false
],
'pluginOptions' => [
'uploadUrl' => Url::toRoute('pesertadidikuploadproses'),
'uploadExtraData' => ['folderId' => ""],
'showUpload' => true
],
'pluginEvents' => [
'fileuploaded' => "function(event, data, previewId, index) {
$('#pesan').show();
$('#pesan').html(data.response.pesan);
}"
]
]);
?>
I want the value of uploadExtraData should be get as serialize data form --> $('#formid').serialize();
Like said in this post, you can't direct access to files on a user computer. One technique is to use and iframe to do the submission and that way you won't have to refresh the page.
So use this plugin and just do something as below:
$(function() {
$('#ifoftheform').ajaxForm(function(result) {
alert('the form was successfully processed');
});
});

ZF2 - Using zfc-rbac for custom route redirection

I am using ZfcRbac and need to add a custom re-direct strategy. I have read the document here re-direct strategy documents but am not 100% sure how to implement an alternative stratergy for my use case:
When a user attempts to enter a route in an admin area I currently redirect back to the admin login page if they are not already logged in.
When a customer logs into their account pages, I need to re-direct them to the customer login pages. Currently they are re-directed to the admin login pages.
My Module.php file has this::
public function onBootstrap(EventInterface $e)
{
$t = $e->getTarget();
$t->getEventManager()->attach(
$t->getServiceManager()->get('ZfcRbac\View\Strategy\RedirectStrategy')
);
}
My Global has this::
<?php
return [
'zfc_rbac' => [
'protection_policy' => \ZfcRbac\Guard\GuardInterface::POLICY_ALLOW,
'guards' => [
'ZfcRbac\Guard\RouteGuard' => [
//ADMIN ACCOUNT GUARDS
'user' => ['admin-master'],
'user/login' => ['guest'],
'user/logout' => ['admin-master', 'merchant-worker', 'guest'],
'user/register' => ['admin-master', 'merchant-admin', 'guest'],
'user/change-password' => ['admin-master', 'merchant-worker'],
'user/forgot-password' => ['guest'],
//CUSTOMER ACCOUNT GUARDS
'customer' => ['customer'],
]
],
'identity_provider' => \RoleBasedUser\Service\AuthenticationService::class,
'role_provider' => [
'ZfcRbac\Role\ObjectRepositoryRoleProvider' => [
'object_manager' => 'doctrine.entitymanager.orm_default',
'class_name' => 'RoleBasedUser\Entity\HierarchicalRole',
'role_name_property' => 'name'
]
],
'redirect_strategy' => [
'redirect_when_connected' => true,
'redirect_to_route_connected' => 'home',
'redirect_to_route_disconnected' => 'user/login',
'append_previous_uri' => true,
'previous_uri_query_key' => 'redirectTo'
],
]
];
To make this work, I believe I need to write a custom stratergy, however I am not 100% certain how to go about this.
This was actually quite easy to solve once I got my head around ZfcRbac. What I did was to create my own RedirectStrategy:: MyRedirectStrategy and to update the config global.
config global: An array of routes and the route to direct to. This could have been made more extensive to include a variety of routes and redirects but I only needed one additional one.
'redirect_to_route_disconnected' => [
'routes' => [
'user','other1','other2'
],
'redirect' => 'user/login'
],
'redirect_to_route_connected' => [
'routes' => [
'user','other1','other2'
],
'redirect' => 'user'
],
Default settings are for Customer pages and the alternative pages are for my admin.
I added the following check to my extended strategy:
if ($event->getRouteMatch()) {
$routeMatch = $event->getRouteMatch()->getMatchedRouteName();
$redirect_to_route_disconnected = $this->sl->get('config')['zfc_rbac']['redirect_to_route_disconnected'];
$redirect_to_route_connected = $this->sl->get('config')['zfc_rbac']['redirect_to_route_connected'];
} else {
$routeMatch = '';
$redirect_to_route_disconnected = array();
$redirect_to_route_connected = array();
}
And then added a check and set:
if ($this->authenticationService->hasIdentity()) {
if (!$this->options->getRedirectWhenConnected()) {
return;
}
if (in_array($routeMatch,$redirect_to_route_connected['routes'])) {
$this->options->setRedirectToRouteConnected($redirect_to_route_connected['redirect']);
}
$redirectRoute = $this->options->getRedirectToRouteConnected();
} else {
if (in_array($routeMatch,$redirect_to_route_disconnected['routes'])) {
$this->options->setRedirectToRouteDisconnected($redirect_to_route_disconnected['redirect']);
}
$redirectRoute = $this->options->getRedirectToRouteDisconnected();
}
I chose to set the customer pages as the default as I have no problem with an admin being directed to the customer pages due to a missed route check.The other way round would serve to confuse the customers.

Resources