hybridauth - can not restore google login - hybridauth

I have made login script with HybridAuth. I'm loged in my website with "providers" Facebook, Google, Twitter. When PHP sessions time out, I want to restore my connected "providers".
I use this code :
$connected_adapters_list = $hybridauth->getConnectedProviders();
if( count( $connected_adapters_list ) ){
foreach( $connected_adapters_list as $adapter_id ){
echo $adapter_id . "<br>";
}
}
HybridAuth can restore my Facebook and Twitter connection, but not Google. This is code error output. How to solve it ?
Ooophs, we got an error: User profile request failed! Google returned an invalid response:stdClass::__set_state(array( 'error' => stdClass::__set_state(array( 'errors' => array ( 0 => stdClass::__set_state(array( 'domain' => 'global', 'reason' => 'authError', 'message' => 'Invalid Credentials', 'locationType' => 'header', 'location' => 'Authorization', )), ), 'code' => 401, 'message' => 'Invalid Credentials', )), )) Error code: 6

I also has this problem,
it could be sloved by using "logoutAllProviders()" function
there is code :
try{
$hybridauth = new Hybrid_Auth( $config );
$adapter = $hybridauth->authenticate( "Google" );
$user_profile = $adapter->getUserProfile();
}
catch( Exception $e ){
$hybridauth->logoutAllProviders();
$hybridauth = new Hybrid_Auth( $config );
$adapter = $hybridauth->authenticate( "Google" );
$user_profile = $adapter->getUserProfile();
}
}
good luck for you !

Related

Laravel 5.4 Mail sending not working when set configuration using config::set facade

I'm sending email using sendgrid smtp It's work fine when i add my credential in the .env file, but i want to store my credential in a table and load and set it using config::set facade my email is not sending and also i'm not getting any error. following is my code:
code where i'm calling the Mail::to and send function
$campaign = Campaign::where('id', $id)->first();
if ($campaign) {
$campaign->status = self::START_STATUS;
$campaign->save();
$list = CampaignList::where('id', $campaign->campaign_list_id)->first();
$template = Template::where('id', $campaign->template_id)->first();
foreach ($list->campaignListMember as $contact) {
$campaignTracking = new CampaignTracking();
$campaignTracking->campaign_id = $campaign->id;
$campaignTracking->company_contact_id = $contact->companyContact->id;
$campaignTracking->email_status = self::PENDING_STATUS;
$campaignTracking->reason = '';
$campaignTracking->save();
Mail::to($contact->companyContact->email)->send(new SendBulkEmails($template, $contact->companyContact,$campaign->id,$this->global->id));
}
}
code wher i'm configuring mail configuration:
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\CampaignSmtpSetting;
use Illuminate\Mail\MailServiceProvider;
use Illuminate\Support\Facades\Config;
class SendBulkEmails extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
public $data;
public $contact;
public $campaignId;
public function __construct($data,$contact,$campaignId,$organisationId)
{
$this->data = $data;
$this->contact = $contact;
$this->campaignId = $campaignId;
$smtpSetting = CampaignSmtpSetting::where('organisation_setting_id',$organisationId)->first();
Config::set('mail.driver', $smtpSetting->mail_driver);
Config::set('mail.host', $smtpSetting->mail_host);
Config::set('mail.port', $smtpSetting->mail_port);
Config::set('mail.username', $smtpSetting->mail_user_name);
Config::set('mail.password', $smtpSetting->mail_password);
Config::set('mail.encryption', $smtpSetting->mail_encryption);
Config::set('mail.from.name', $smtpSetting->mail_from_name);
Config::set('mail.from.address', $smtpSetting->mail_from_email);
(new MailServiceProvider(app()))->register();
// print_r(Config::get('mail'));exit;
}
public function build()
{
$this->data->body = str_replace('{FIRSTNAME}',$this->contact->first_name,$this->data->body);
$this->data->body = str_replace('{LASTNAME}',$this->contact->last_name,$this->data->body);
$this->data->body = str_replace('{EMAIL}',$this->contact->email,$this->data->body);
$path = public_path() . '/user-uploads/template-attachments/';
$email = $this->view('admin.send-bulk-emails.email',['body' => $this->data->body])
->subject($this->data->subject);
foreach ($this->data->attachments as $attachment){
$path .= $attachment->file_name;
$email->attach($path);
}
if (!$this->data->cc == ''){
$email->cc($this->data->cc);
}
if (!$this->data->bcc == ''){
$email->bcc($this->data->bcc);
}
return $email;
}
when i use print_r(Config::get('mail')) i get the configuration like below
Array
(
[driver] => smtp
[host] => smtp.sendgrid.net
[port] => 587
[from] => Array
(
[address] => hidayat.ullah#piecyfer.com
[name] => Hidayat
)
[encryption] => tls
[username] => hidayat3676
[password] => password
[sendmail] => /usr/sbin/sendmail -bs
[markdown] => Array
(
[theme] => default
[paths] => Array
(
[0] => E:\xampp\htdocs\hrm\resources\views/vendor/mail
)
)
[stream] => Array
(
[ssl] => Array
(
[verify_peer] =>
[verify_peer_name] =>
[allow_self_signed] => 1
)
[tls] => Array
(
[verify_peer] =>
[verify_peer_name] =>
[allow_self_signed] => 1
)
)
)
which seem to be correct, but email sending is not working nor i get any error
Note! if i put the same credential in .env file everything is fine and email sending correctly what could be causing this issue any help is extremely appreciated.

Get Reports On Ads Using Google Ads Api

I am trying to get the reports for campaigns and ads performance.
So far i have gotten the campaign performance reports, but i am unable to to get ads performance reports.
I have seen the google ads api and and their examples in client library. But i am unable to understand how to get ad reports.
I making a function that will fetch the reports for me via google ads api.
Google Ads Api: https://developers.google.com/google-ads/api/docs/fields/ad_group_ad#ad_group_adadexpanded_text_addescription2
Google Ads Api Github: https://github.com/googleads/google-ads-php/
public function getAdsPerformance($customerId)
{
// Customer ID which i am using ---> 2942416690
try {
// Creates a query that retrieves all campaigns.
$query = 'SELECT ad_group_ad.ad.expanded_text_ad.description2 FROM ad_group_ad';
// Issues a search request by specifying page size.
$response = $this->googleAdsServiceClient->search($customerId, $query, ['pageSize' => $this->page_size]);
// Iterates over all rows in all pages and prints the requested field values for
// the campaign in each row.
foreach ($response->iterateAllElements() as $googleAdsRow) {
$adGroup = $googleAdsRow->getAdGroupAd();
// $customer = $googleAdsRow->getCustomer();
// $metrics = $googleAdsRow->getMetrics();
/** #var GoogleAdsRow $googleAdsRow */
$result = [
'ad' => $adGroup->getResourceName()->getValue(),
];
print "<pre>";
print_r($result);
print "</pre>";
}
} catch (GoogleAdsException $googleAdsException) {
printf(
"Request with ID '%s' has failed.%sGoogle Ads failure details:%s",
$googleAdsException->getRequestId(),
PHP_EOL,
PHP_EOL
);
foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
$error = [
'code' => $error->getErrorCode()->getErrorCode(),
'status' => $error->getStatus(),
'message' => $error->getMessage()
];
printf(json_encode($error));
}
} catch (ApiException $apiException) {
$error = [
'code' => $apiException->getCode(),
'status' => $apiException->getStatus(),
'message' => $apiException->getBasicMessage()
];
printf(json_encode($error));
}
}
I am trying to get this type of simple values from api in array
Array
(
[campaign] => some test campaign
[currency] => PLN
[clicks] => 100
[impressions] => 300
[cost] => 250.08
[avg_position] => 1.07
[avg_cpc] => 0.8
[conversions] => 0
[cost/conv] => 0
[conv_rate] => 0
[ctr] => 0.9
[avg_cpm] => 2.5
[interaction_rate] => 0.1
[interactions] => 52
)
Any idea about how can i get the ad reports from the api, Anybody done it? I can't seem to figure out seeing documentation and the client library.
Well, i did it with some research. There are two types of ads.
1. Expanded Text Ads
2. Call only Ads
I checked what was the type of my ad running, and it was 'Expanded Text Ads'. And then picked the field ad_group_ad.ad.expanded_text_ad.headline_part1 from the api documentation from here:
https://developers.google.com/google-ads/api/docs/fields/ad_group_ad#ad_group_adadexpanded_text_adheadline_part1
this is complete function:
public function getAdsPerformance($customerId)
{
try {
$query =
'SELECT ad_group_ad.ad.expanded_text_ad.headline_part1 '
. 'FROM ad_group_ad '
. 'WHERE ad_group_ad.ad.type = EXPANDED_TEXT_AD';
$response = $this->googleAdsServiceClient->search($customerId, $query, ['pageSize' => $this->page_size]);
foreach ($response->iterateAllElements() as $googleAdsRow) {
$ad = $googleAdsRow->getAdGroupAd()->getAd();
$result = [
'headline part 1' => $ad->getExpandedTextAd()->getHeadlinePart1()->getValue(),
];
print "<pre>";
print_r($result);
print "</pre>";
}
} catch (GoogleAdsException $googleAdsException) {
printf(
"Request with ID '%s' has failed.%sGoogle Ads failure details:%s",
$googleAdsException->getRequestId(),
PHP_EOL,
PHP_EOL
);
foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
$error = [
'code' => $error->getErrorCode()->getErrorCode(),
'status' => $error->getStatus(),
'message' => $error->getMessage()
];
// return $error;
printf(json_encode($error));
}
} catch (ApiException $apiException) {
$error = [
'code' => $apiException->getCode(),
'status' => $apiException->getStatus(),
'message' => $apiException->getBasicMessage()
];
printf(json_encode($error));
}
}
And i got the field result:
Array
(
[headline part 1] => Small Business System
)

Get sold items from Ebay SDK Selling - getting “Missing required input element” Error

I cant create a tag for EbaySDK, so Ebay API may be misleading. The SDK reference is below.
Why do some requests require "input" and where can they be found? The SDK notes don't seem clear on whats required per "call type".
Following the examples from http://devbay.net/sdk/guides/getting-started/basic-usage.html#working-with-responses I'm attempting to get a list of sold items. Since Ebay only keeps 90 days data, I've put no restrictions on my request.
Their example request is:
// Create the API request object.
$request = new Types\FindItemsByKeywordsRequest();
// Assign the keywords.
$request->keywords = 'Harry Potter';
// Output the response from the API.
if ($response->ack !== 'Success') {
foreach ($response->errorMessage->error as $error) {
printf("Error: %s\n", $error->message);
}
} else {
foreach ($response->searchResult->item as $item) {
printf("(%s) %s:%.2f\n", $item->itemId, $item->title, $item->sellingStatus->currentPrice->value);
}
}
mine is a bit more simple (and apparently incomplete)
$request = new Types\GetItemStatusRequestType;
$response = $service->getItemStatus();
if ($response->Ack !== 'Success') {
if (isset($response->Errors)) {
foreach ($response->Errors as $error) {
printf("Error: %s\n", $error->ShortMessage);
}
}
} else {
print_r($response->getItemStatus); //should return all avail values (works with other types of requests)
}
Here is the nasty error
DTS\eBaySDK\Shopping\Types\GetItemStatusResponseType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[Timestamp] => DateTime Object
(
[date] => 2016-03-23 00:28:28.391000
[timezone_type] => 2
[timezone] => Z
)
[Ack] => Failure
[Errors] => DTS\eBaySDK\Types\UnboundType Object
(
[data:DTS\eBaySDK\Types\UnboundType:private] => Array
(
[0] => DTS\eBaySDK\Shopping\Types\ErrorType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[ShortMessage] => Missing required input element.
[LongMessage] => Required input element is missing from the request.
[ErrorCode] => 1.19
[SeverityCode] => Error
[ErrorParameters] => DTS\eBaySDK\Types\UnboundType Object
(
[data:DTS\eBaySDK\Types\UnboundType:private] => Array
(
[0] => DTS\eBaySDK\Shopping\Types\ErrorParameterType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[ParamID] => 0
[Value] => ItemID
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
)
[position:DTS\eBaySDK\Types\UnboundType:private] => 0
[class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Shopping\Types\ErrorType
[property:DTS\eBaySDK\Types\UnboundType:private] => ErrorParameters
[expectedType:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Shopping\Types\ErrorParameterType
)
[ErrorClassification] => RequestError
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
)
[position:DTS\eBaySDK\Types\UnboundType:private] => 0
[class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Shopping\Types\GetItemStatusResponseType
[property:DTS\eBaySDK\Types\UnboundType:private] => Errors
[expectedType:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Shopping\Types\ErrorType
)
[Build] => E949_CORE_APILW_17769283_R1
[Version] => 949
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
Error: Missing required input element.
It seems I'm not asking the request for something, but I have no idea.
The GetItemStatus call requires you provide an ItemID. See the following API reference: GetItemStatus
You state you are looking for a sales history. I don't believe this is the call you should be using. This is a function call that appears to be in the shopping API, which is more of a product search tool.
You probably want to be using 'GetOrders' API call if you are looking to get a particular accounts sales history. See the following: GetOrders

Missing or invalid url parameter while posting image with twitter API

I am trying to post image on twitter. Image is already in my server. Here is my code
$tweet_img = '/home/voucherscode/public_html/editsocial/'.$tweet_img;
$returnT = $connection->post('statuses/update_with_media', array(
'media[]' => file_get_contents($tweet_img),
'status' => "$tweet_msg"
));
But I am response as
stdClass Object(
[errors] => Array
(
[0] => stdClass Object
(
[code] => 195
[message] => Missing or invalid url parameter.
)
))
Please help.
I got the issue. I was using old twitteroauth and on that post function has not multipart parameter.
I replaced my twitteroauth with https://github.com/tomi-heiskanen/twitteroauth/blob/77795ff40e4ec914bab4604e7063fa70a27077d4/twitteroauth/twitteroauth.php and it works with below code.
$tweet_img = '/home/voucherscode/public_html/editsocial/'.$tweet_img;
$handle = fopen($tweet_img,'rb');
$image = fread($handle,filesize($tweet_img));
fclose($handle);
$parameters = array('media[]' => "{$image};type=image/jpeg;filename={$tweet_img}",'status' => 'Picture time');
$returnT = $connection->post('statuses/update_with_media', $parameters, true);

The push notification format of Pushwoosh and Phonegap

Now the pushwoosh works without problem. I can see the notification on the upper left corner of the Android phone. How can I set the notification to be pop-up onto screen rather than the notification on upper left only, even the phone is in silence mode!
Which way should I go for the customization? Thx
function pwCall( $action, $data = array() ) {
$url = 'https://cp.pushwoosh.com/json/1.3/' . $action;
$json = json_encode( array( 'request' => $data ) );
$res = doPostRequest( $url, $json, 'Content-Type: application/json' );
print_r( #json_decode( $res, true ) ); }
pwCall( 'createMessage', array( '
application' => PW_APPLICATION,
'auth' => PW_AUTH,
'notifications' => array(
array(
'send_date' => 'now',
'content' => 'test',
'ios_badges' => 3,
'data' => array( 'custom' => 'json data' ),
'link' => 'http://pushwoosh.com/'
)
)
)
);
To configure how to display the incoming push notification, you should write your own logic in the receiver in Android app, as specified in this page.
Currently, the tutorial currently uses the following the show the message:
private void showMessage(String message)
{
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
Try to create your own logic (user interface, popup method & timing, etc) in the function.

Resources