I can't reach customers AdWords Account with Google Login - google-ads-api

I want to connect -any- customer Google AdWords Account with Google Login. (Like Wordstream)
I prepared a code, but there is a problem somewhere, I can't run it.
When the customer press the connect button, the screen appears. It says "XXX wants to acces your Google Account", it is approved but I cannot receive data.
How can i get datas from customer's account?
Code:
require 'google-api/vendor/autoload.php';
use Google\Auth\OAuth2;
use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201809\cm\CampaignService;
use Google\AdsApi\Common\OAuth2TokenBuilder;
session_start();
$oauth2 = new OAuth2([
'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth',
'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',
'redirectUri' => 'https://xxxxx.xxxxxx',
'clientId' => 'xxxxxxxxx.apps.googleusercontent.com',
'clientSecret' => 'xxxxxxxxxxx',
'scope' => 'https://www.googleapis.com/auth/adwords',
'refresh_token' => 'xxxxxxxxxx'
]);
if(!isset($_GET['code'])){
$oauth2->setState(sha1(openssl_random_pseudo_bytes(1024)));
$_SESSION['oauth2state'] = $oauth2->getState();
$config = [
'access_type' => 'offline',
'prompt' => 'consent',
];
header('Location: ' . $oauth2->buildFullAuthorizationUri($config));
exit;
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])){
unset($_SESSION['oauth2state']);
exit('Invalid state.');
} else {
$oauth2->setCode($_GET['code']);
$authToken = $oauth2->fetchAuthToken();
$refreshToken = $authToken['refresh_token'];
$path = "xxxxx/google-api/vendor/adsapi_php.ini";
$session = (new AdWordsSessionBuilder())
->fromFile($path)
->withOAuth2Credential($oauth2)
->build();
$adWordsServices = new AdWordsServices();
$campaignService = $adWordsServices->get($session, CampaignService::class);
print_r($campaignService);
}

Related

Webklex\PHPIMAP Modern Auth Not Working 365

As with most people, Microsoft are turning off basic authentication. This means we need to use Modern Auth to retrieve emails from a mailbox.
However,when we retrie the access token fails with "
Client error: `POST https://login.microsoftonline.com/aea9a7d8-73fb-41af-987b-6fe14277421e/oauth2/v2.0/token` resulted in a `400 Bad Request` response:\n
{"error":"unauthorized_client","error_description":"AADSTS700016: Application with identifier '\"014438b9-82dc-4a4c-9584 (truncated...)
"
Here is the code we have for retrieving and connecting to IMAP. I am passing actual email and password in usename and password field
/* Get the access Token */
$Secret = '**REMOVED**';
$AppID = '**REMOVED**';
$TenantID = '**REMOVED**';
$AccessToken = '';
try {
$guzzle = new \GuzzleHttp\Client(['headers' => ['User-Agent' => 'App-Token-Request']]);
$url = 'https://login.microsoftonline.com/'.$TenantID.'/oauth2/v2.0/token';
$token = json_decode($guzzle->post($url, [
'form_params' => [
'grant_type' => 'password',
'client_id' => $AppID,
'client_secret' => $Secret,
'scope' => 'https://graph.microsoft.com/.default', //'https://outlook.office365.com/IMAP.AccessAsUser.All',// 'https://graph.microsoft.com/.default',
'username' => '**REMOVED**',
'password' => '**REMOVED**',
],
])->getBody()->getContents());
$this->info(var_dump($token));
$AccessToken = $token->access_token;
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
dd($e);
return redirect('/')->with('error', 'Error requesting access token')->with('errorDetail', json_encode($e->getResponseBody()));
}

Dailymotion API PHP Upload with Geoblocking

i'm try to write dailymotion api upload php code
i'm use example code from https://developer.dailymotion.com/guides
it's work great
and i want add Geoblocking only allow Japan
this is my code
require_once 'Dailymotion.php';
// Account settings
$apiKey = 'xxxxxxxxxxxxxxxxxx';
$apiSecret = 'xxxxxxxxxxxxxxxxxx';
$testUser = 'xxxxxxxxxxxxxxxxxx#xxxx.com';
$testPassword = 'xxxxxxxxxxxxxxxxxx';
$videoTestFile = 'C:/output.mp4';
// Scopes you need to run your tests
$scopes = array(
'userinfo',
'feed',
'manage_videos',
);
// Dailymotion object instanciation
$api = new Dailymotion();
$api->setGrantType(
Dailymotion::GRANT_TYPE_PASSWORD,
$apiKey,
$apiSecret,
$scopes,
array(
'username' => $testUser,
'password' => $testPassword,
)
);
$url = $api->uploadFile($videoTestFile);
$result = $api->post(
'/videos',
array(
'url' => $url,
'title' => 'Dailymotion PHP SDK upload test 2',
'tags' => 'dailymotion,api,sdk,test',
'channel' => 'videogames',
'published' => true,
'geoblocking' => 'JP', // i'm add this line
)
);
var_dump($result);
but i got this error
Fatal error: Uncaught exception 'DailymotionAuthRequiredException' with message 'Insufficient rights for the `geoblocking' parameter of route `POST /videos'. Required scopes: manage_videos'
anyone can tell me
what i'm doing wrong and help me fix this problem
thank you
'geoblocking' => 'JP'
change to 'geoblocking' => 'jp'
your code will be
require_once 'Dailymotion.php';
// Account settings
$apiKey = 'xxxxxxxxxxxxxxxxxx';
$apiSecret = 'xxxxxxxxxxxxxxxxxx';
$testUser = 'xxxxxxxxxxxxxxxxxx#xxxx.com';
$testPassword = 'xxxxxxxxxxxxxxxxxx';
$videoTestFile = 'C:/output.mp4';
// Scopes you need to run your tests
$scopes = array(
'userinfo',
'feed',
'manage_videos',
);
// Dailymotion object instanciation
$api = new Dailymotion();
$api->setGrantType(
Dailymotion::GRANT_TYPE_PASSWORD,
$apiKey,
$apiSecret,
$scopes,
array(
'username' => $testUser,
'password' => $testPassword,
)
);
$url = $api->uploadFile($videoTestFile);
$result = $api->post(
'/videos',
array(
'url' => $url,
'title' => 'Dailymotion PHP SDK upload test 2',
'tags' => 'dailymotion,api,sdk,test',
'channel' => 'videogames',
'published' => true,
'geoblocking' => 'jp' // NO , in last line
)
);
var_dump($result);

How to save ZfcUser display name

I'm trying to save the display name of a user account using ZfcUser as a base to create my own API, but unfortunately I couldn't. This is my code:
$service = $this->getUserService();
$form = $this->getPostData();
$post = array(
"email" => $form->{'email'},
"password" => $form->{'password'},
"passwordVerify" => $form->{'password'},
"display_name" => $form->{'name'},
"submit" => ""
);
$service->register($post);
return new JsonModel($this->postToArray($form));

home_timeline missing tweets - API 1.1

I used the following code to try to grab tweets from my home_timeline
$tmhOAuth = new tmhOAuth(array('consumer_key' => TW_KEY,
'consumer_secret' => TW_SECRET,
'user_token' => TW_UTOKEN,
'user_secret' => TW_USECRET,
));
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/home_timeline', 'json'));
The $tmhOAuth came from this library here: https://github.com/themattharris/tmhOAuth
For some reason, only one tweet is showing, and it's my most recent one. All my old tweets are not visible. When I change the secrets and keys to that of another user-app, i have similar problme, some tweets are visible while others are not. Does anyone know why it doesnt' just grab all X number of the most recent tweets? Why are some tweets missing?
I download Jimbo's API from github and then did hte following code
<?php
ini_set('display_errors', 1);
require_once('twjimbo/TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "",
'oauth_access_token_secret' => "",
'consumer_key' => '',
'consumer_secret' => ""
);
]
$url = 'https://api.twitter.com/1.1/statuses/home_timeline.json';
$getfield = '?screen_name=anythingworkshere';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$json = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
echo '<pre>'; print_r(json_decode($json)); echo '</pre>';

Delicious PHP oAuth Yahoo SDK Add Bookmark

I'm really having a difficult time trying to find a way to successfully authenticate a user and post a bookmark to their delicious account.
I downloaded Yahoo's YOS Social SDK then began modifying the oauth sampleapp.php. It basically handles the oAuth process by creating a login link that sends you to Yahoo to grant permission then sends you back to the callback URL you specify.
My thought was to modify the sampleapp.php file to make a request to delicious posts/add API to add a new bookmark once they oAuth process is over, but I'm running into some problems. I think I'm handling the POST request in the wrong manner.
Here is my code:
<?php
require dirname(__FILE__).'/lib/Yahoo.inc';
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', true);
YahooLogger::setDebug(true);
YahooLogger::setDebugDestination('LOG');
ini_set('session.save_handler', 'files');
session_save_path('/tmp/');
session_start();
define('OAUTH_CONSUMER_KEY', '<YOURS_GOES_HERE>');
define('OAUTH_CONSUMER_SECRET', '<YOURS_GOES_HERE>');
define('OAUTH_DOMAIN', '<YOURS_GOES_HERE>');
define('OAUTH_APP_ID', '<YOURS_GOES_HERE>');
if(array_key_exists("logout", $_GET)) {
YahooSession::clearSession();
header("Location: sampleapp.php");
}
$hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
if($hasSession == FALSE) {
$callback = YahooUtil::current_url();
$auth_url = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback);
}
else {
$session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
if($session) {
$consumer = new stdclass();
$consumer->key = OAUTH_CONSUMER_KEY;
$consumer->secret = OAUTH_CONSUMER_SECRET;
$nativeSession = new NativeSessionStore();
$token = $nativeSession->fetchAccessToken();
$client = new OAuthClient($consumer, $token, OAUTH_PARAMS_IN_HEADERS, OAUTH_SIGNATURE_HMAC_SHA1);
$request_url = 'http://api.del.icio.us/v2/posts/add';
$bookmark_url = 'http://www.tegdesign.com';
$parameters = array("url" => urlencode($bookmark_url), "description" => "test");
$response = $client->post($request_url,'TEXT',$parameters);
echo '<pre>';
print_r($response);
echo '</pre>';
}
}
if($hasSession == FALSE) {
echo sprintf("Login\n", $auth_url);
} else if($hasSession) {
echo "<p>Logout</p>";
}
?>
And here is the output of $response variable:
Array
(
[method] => POST
[url] => http://api.del.icio.us/v2/posts/add
[code] => 401
[requestHeaders] => Array
(
[0] => Accept: application/json
[1] => Authorization: OAuth realm="yahooapis.com",oauth_version="1.0",oauth_nonce="<MINE_SHOWS_HERE>",oauth_timestamp="1289407587",oauth_consumer_key="<MINE_SHOWS_HERE>",oauth_token="<MINE_SHOWS_HERE>",oauth_signature_method="HMAC-SHA1",oauth_signature="<MINE_SHOWS_HERE>"
[2] => Content-Type: TEXT
)
[requestBody] => Array
(
[url] => http%3A%2F%2Fwww.tegdesign.com
[description] => test
)
[responseHeaders] => Array
(
[Date] => Wed, 10 Nov 2010 16:46:32 GMT
[WWW-Authenticate] => OAuth oauth_problem="signature_invalid", realm="yahooapis.com"
[Content-Type] => application/json
[Cache-Control] => private
[Age] => 0
[Transfer-Encoding] => chunked
[Connection] => keep-alive
[Server] => YTS/1.17.21
)
[responseBody] => {"error":{"lang":"en-US","description":"Please provide valid credentials"}}
)
Does anybody have knowledge on using Delicious new API to successfully authenticate and post a bookmark on behalf a user? I'm having a terrible time.
Thanks,
Tegan
Set your content type to "application/x-www-form-urlencoded" instead of 'Text' on the below line.
$response = $client->post($request_url,'TEXT',$parameters);

Resources