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>';
Related
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);
}
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);
i want to exclude some mention users while sending the tweet so i mentioned in the code as exclude_reply_user_ids and passing this parameter to /statuses/update.json. But still i cant exclude users after tweeting reply.
So Here is my code :
$params = array(
'status' => $message,
'auto_populate_reply_metadata' => 'true',
'tweet_mode' => 'extended',
'in_reply_to_status_id' => $status_id,
'in_reply_to_screen_name' => $screenname,
'exclude_reply_user_ids' => $exids
);
$res = $tmhOAuth->request('POST', $config->twitter_api_url . '/statuses/update.json',
$params,
true,
true
);
[output][1]
[output][2]
[output][3]
[output][4]
[output][5]
[1]: https://i.stack.imgur.com/Yfmvs.png
[2]: https://i.stack.imgur.com/zUMx2.png
[3]: https://i.stack.imgur.com/VfzEL.png
[4]: https://i.stack.imgur.com/9XQYr.png
[5]: https://i.stack.imgur.com/z3QCy.png
In regards to using SOAP to connect to Sugar CRM, the documentation for Sugar 6.1 Community Edition states:
"See /examples/SugarFullTest_Version2.php for more examples on usage."
source:
http://developers.sugarcrm.com/docs/OS/6.1/-docs-Developer_Guides-Sugar_Developer_Guide_6.1.0-Chapter%202%20Application%20Framework.html#9000244
This file is not in the examples folder. Where is it?
If this file does not exist, where can I find a working example of connecting to Sugar CRM with SOAP? None of the test scripts in the /examples/ folder work.
Couldn't find the file either, so made an example (PHP script connecting to sugarCRM v6 SOAP) for you.
<?php
require_once('include/nusoap/lib/nusoap.php');
$myWsdl = 'http://mysite.com/soap.php?wsdl';
$myAuth = array(
'user_name' => 'xxxx',
'password' => MD5('xxxx'),
'version' => '0.1'
);
$soapClient = new nusoap_client($myWsdl,true);
// Create lead
// (Can be made without login, i.e. sessionid)
$leadParams = array('user_name' => 'xxxx',
'password' => MD5('xxxx'),
'first_name' => 'Test',
'last_name' => '2',
'email_address' => '2#'
);
$leadResult = $soapClient->call('create_lead', $leadParams);
$leadId = $leadResult;
print_r($leadResult);
// Login
$loginParams = array('user_auth' => $myAuth, 'application_name' => 'WebForm');
$loginResult = $soapClient->call('login', $loginParams);
$sessionId = $loginResult['id'];
// Modules
// (Need login, so sessionID is used)
$modulesResult = $soapClient->call('get_available_modules', array('session' => $sessionId));
print_r($modulesResult);
// Get account list
$accountParams = array('session' => $sessionId,
'module_name' => 'Accounts',
'query' => "accounts.name = 'Amarelo'",
'order_by' => '',
'deleted' => 0
);
$accountResult = $soapClient->call('get_entry_list', $accountParams);
print_r($accountResult);
// Get entry
$leadParams = array('session' => $sessionId,
'module_name' => 'Leads',
'id' => "$leadId"
);
$leadResult = $soapClient->call('get_entry', $leadParams);
print_r($leadResult);
// Logout
$logoutResult = $soapClient->call('logout', array('session' => $sessionId));
?>
For debugging and testing SoapUI is very helpful.
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);