Yahoo api is not fetching contacts somehow - yahoo

I've following code to retrieve yahoo contacts through its api however it's not fetching any contacts.
Here's my code:
session_start();
include_once 'config.php'; //This file contains consumer key & all data
require_once ('Yahoo.inc'); //This is a standard Yahoo file, just copied it
$session = YahooSession::requireSession($consumer_key,$consumer_secret,$app_id);
if (is_object($session))
{
$user = $session->getSessionedUser(); //This is NOT NULL
$profile = $user->getProfile(); //This is NULL
$name = $profile->givenNme;
$guid = $profile->guid;
$contacts=$user->getContacts()->contacts; //This is NULL
if($contacts==NULL){
echo "No contacts";
}
}
Somehow getProfile() & getContacts() are not working properly. Any idea why it's not working?

Related

I wanted to fetch data from database while sending an email instead of hardcoded email in codeigniter

I wanted to fetch data from database while sending an email instead of hardcoded email in codeigniter
function send_user_email_missing_doc_test($to, $subject, $body, $attachment = null,$cc = NULL, $bcc = NULL,$bcc2 = NULL)
{
$this->load->library('email');
$this->email->clear(TRUE);
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from('Greetings#investorsloanservicing.com', 'Sharestates');
//$this->email->reply_to('Kevin#investorsloanservicing.com','');
$this->email->reply_to('Allen#investorsloanservicing.com');
if ($cc != '') {
$this->email->cc('help#ssapp.support');
}
if ($bcc != '') {
// $ary=array('prinuannie#gmail.com,hemaravi7878#gmail.com');
$ary=array('help#ssapp.support,Allen#investorsloanservicing.com');
$this->email->bcc($ary);
}
if ($bcc2 != '') {
//$ary=array('prinuannie#gmail.com,hemaravi7878#gmail.com');
$ary=array('help#ssapp.support');
$this->email->bcc($ary);
}
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($body);
if (isset($attachment) && !empty($attachment)) {
foreach ($attachment as $path) {
$this->email->attach($path);
}
}
$this->email->send();
}
the above code is my model page.I wanted to fetch email from the database instead of hardcoded Greetings#investorsonlineservicing.com
how to fetch data from database and get it in my model page and controller page,and i have manually only inserted the email id in database.i just want the data to be fetched instead of that Greetings#investorsloanservicing.com
Any help will be appreciated.
*database name is loanservice_sharestates and table name is common_email_settings which have id,title ,name,value ----values are given below----------- 1 , Greeting Mail , greeting_email , Greetings#investorsloanservicing.com *

Composer and Php Google Api Client

This is my composer.json:
{
"require": {
"google/apiclient": "1.0.*#beta"
}
}
And this is my code:
<?
$path = get_include_path() . PATH_SEPARATOR . 'C:\wamp\www\gCalendar\vendor\google\apiclient\src';
set_include_path($path);
define("APIKEY","AIxxxxxxxWA");
define("CLIENTID","xxxkqt.apps.googleusercontent.com");
define("CLIENTSECRET","xxxx");
define("DEVELOPERKEY","xxx.apps.googleusercontent.com");
require_once("config.php");
require_once("vendor/autoload.php");
session_start();
$scriptUri = "http://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF'];
$client = new Google_Client();
$client->setAccessType('online'); // default: offline
$client->setApplicationName('CalendarTest');
$client->setClientId(CLIENTID);
$client->setClientSecret(CLIENTSECRET);
$client->setRedirectUri($scriptUri);
$client->setDeveloperKey(APIKEY); // API key
// $service implements the client interface, has to be set before auth call
$service = new Google_AnalyticsService($client);
if (isset($_GET['logout'])) { // logout: destroy token
unset($_SESSION['token']);
die('Logged out.');
}
if (isset($_GET['code'])) { // we received the positive auth callback, get the token and store it in session
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
}
if (isset($_SESSION['token'])) { // extract token from session and configure client
$token = $_SESSION['token'];
$client->setAccessToken($token);
}
if (!$client->getAccessToken()) { // auth call to google
$authUrl = $client->createAuthUrl();
header("Location: ".$authUrl);
die;
}
echo 'Hello, world.';
?>
I have returned this error:
( ! ) Fatal error: Class 'Google_AnalyticsService' not found in C:\wamp\www\gCalendar\index.php on line 21
What I am doing wrong including the library with Composer?
Thank you so much
The class Google_AnalyticsService does not exist in that library. Try Google_Service instead.
$service = new Google_Service($client);
I know this is old, but I see no answer, and there is not enough about this out there... Does setting the scope to 'https://www.googleapis.com/auth/analytics' help?
All scopes found here:
https://developers.google.com/identity/protocols/googlescopes
<?php
session_start();
$_SESSION = [];
require_once 'vendor/autoload.php';//Composer generated autoload.php(not Google/autoload.php)
$google_api_key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
$clientID = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.apps.googleusercontent.com";
$clientSecret = "AAAAAAAAAAAAAAAAAAAAAAAA";
$scriptUri = "https://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF'];
$client = new Google_Client();
$client->setAccessType('online');
$client->setApplicationName('MYAPPNAME');
$client->setClientId($clientID );
$client->setClientSecret($clientSecret);
$client->setRedirectUri($scriptUri);
$client->setDeveloperKey($google_api_key);
$client->addScope('https://www.googleapis.com/auth/analytics');
$service = new Google_Service($client);
if (isset($_GET['logout']))
{
unset($_SESSION['token']);
die('Logged out.');
}
if (isset($_GET['code']))
{
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
}
if (isset($_SESSION['token']))
{
$token = $_SESSION['token'];
$client->setAccessToken($token);
}
if (!$client->getAccessToken())
{
$authUrl = $client->createAuthUrl();
header("Location: ".$authUrl);
die;
}
echo "<pre>";
print_r($_SESSION);
echo "</pre>";
echo 'Hello, world.';
?>
The class used to exists and still get copy pasted along.
Use Google_Service_Analytics now.
In version ^2.0 use like this
// Use the developers console and download your service account
// credentials in JSON format. Place them in this directory or
// change the key file location if necessary.
$KEY_FILE_LOCATION = __DIR__ . '/service-account-credentials.json';
// Create and configure a new client object.
$client = new Google_Client();
$client->setApplicationName("Hello Analytics Reporting");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
$analytics = new Google_Service_AnalyticsReporting($client);
...

Add user to group in Joomla not working

I am trying to add a user to a group. I can run this PHP code without any errors, but the user group is still not changed.
<?php
define('_JEXEC', 1);
define('JPATH_BASE', realpath(dirname(__FILE__)));
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
require_once ( JPATH_BASE .'/libraries/joomla/factory.php' );
$userId = 358;
$groupId = 11;
echo JUserHelper::addUserToGroup($userId, $groupId);
?>
I run in the same issue with payment callback. I found that user groups save in the database correctly, but are not refreshed in Juser object (becouse You add user to group in different session). When user interacts on a page groups are restored.
Another think that i found is that changing groups in administrator panel works the same way if user is logged in.
To deal with it I made system plugin and in onAfterInitialise function i do:
//get user
$me = JFactory::getUser();
//check if user is logged in
if($me->id){
//get groups
$groups = JUserHelper::getUserGroups($me->id);
//check if current user object has right groups
if($me->groups != $groups){
//if not update groups and clear session access levels
$me->groups = $groups;
$me->set('_authLevels', null);
}
}
Hope it will help.
Possible "Easy" Solution:
The code is correct and it should put your $userId and $groupId in the db to be precise in #__user_usergroup_map .
Btw consider that this method is rising an error if you use a wrong groupId but it's not raising any error if you insert a wrong $userId and for wrong I mean that it doesn't exist.
So there are canches that the user with $userId = 358; doesn't exist.
Update - Hard Debugging:
Ok in this case I suggest you to digg in the code of the helper.
The file is :
libraries/joomla/user/helper.php
On line 33 You have JUserHelper::addUserToGroup.
This is the code:
public static function addUserToGroup($userId, $groupId)
{
// Get the user object.
$user = new JUser((int) $userId);
// Add the user to the group if necessary.
if (!in_array($groupId, $user->groups))
{
// Get the title of the group.
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__usergroups'))
->where($db->quoteName('id') . ' = ' . (int) $groupId);
$db->setQuery($query);
$title = $db->loadResult();
// If the group does not exist, return an exception.
if (!$title)
{
throw new RuntimeException('Access Usergroup Invalid');
}
// Add the group data to the user object.
$user->groups[$title] = $groupId;
// Store the user object.
$user->save();
}
if (session_id())
{
// Set the group data for any preloaded user objects.
$temp = JFactory::getUser((int) $userId);
$temp->groups = $user->groups;
// Set the group data for the user object in the session.
$temp = JFactory::getUser();
if ($temp->id == $userId)
{
$temp->groups = $user->groups;
}
}
return true;
}
The bit that save the group is $user->save();.
Try to var_dump() till there and see where is the issue.
Author already halfish solved this problem so this answer may help to others. It took me hours of debugging with Eclipse and XDebug to find the issue. This error was very tricky because addUserToGroup() was returning true for me and user object was as well with successful changes, but they were not saved in database. The problem was that onUserBeforeSave() method in my plugin was throwing exception whenever addUserToGroup() was trying to save a user. So check your implementation of onUserBeforeSave() if you touched it. If not you must install Eclipse with XDebug and try to debug what is your exact problem.

Get K2 extra fields data in external script

Im trying to load data from extra_fields field from k2_items table inside external php script (let's call it locations.php) which I would like to include somewhere else on the site.
Data in extra_field field is json encoded:
[{"id":"1","value":"somevalue"},{"id":"2","value":"somevalue"},{"id":"3","value":"somevalue"}.]
For example: I have items with ids 1,6,10,15,22,44 and 66.
I would like to have variables for each extra field and for each item so I can use them elsewhere.
If item with id 1 has 3 extra fields, I would like to have variables $item1ExtraField1, $item1ExtraField2 and $item1ExtraField3.
So first I initiated Joomla framework:
// Get Joomla Framework
defined('_JEXEC') or die('Restricted access');
define( 'JPATH_BASE', realpath(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );
require_once (JPATH_BASE.DS.'includes'.DS.'defines.php' );
require_once (JPATH_BASE.DS.'includes'.DS.'framework.php' );
require_once (JPATH_BASE.DS.'libraries'.DS.'joomla'.DS.'factory.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
Then I tried DB query with 2 ids to see if I can get data:
// Load the data from the database.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select('extra_fields')
->from('#__k2_items')
->where('id = 15 or id= 289');
$db->setQuery($query);
$items = $db->loadObjectList();
// Check for a database error.
if ($db->getErrorNum())
{
$this->_subject->setError($db->getErrorMsg());
return false;
}
Then I get slowly lost.
I get no results if I try:
foreach ($items as $item) {
echo json_decode($item);
}
and var_dump gives me
array(2) { [0]=> object(stdClass)#1395 (1) { ["extra_fields"]=> string(1013) "[{"id":"3","value":"somevalue"},{"id":"4","value":"somevalue"}, etc ]
or using jdump extension:
[array] (unknown name)
[stdClass object] 0
Properties
[string] extra_fields = "[{"id":"3","value":"somevalue"},{"id":"4","value":"somevalue"}, etc ]"
[stdClass object] 1
Properties
[string] extra_fields = "[{"id":"3","value":"somevalue"},{"id":"4","value":"somevalue"}, etc ]"
So Joomla framework initialization seems ok, DB connection is there, but I'm not sure how to continue.
Any help would be appreciated.
I see the problem is with decoding json string. Try something like this:
$query = mysql_query($sql,$con);
while ($item = mysql_fetch_array($query))
{
$fields =(array)json_decode($item['extra_fields']);
$field1 = $fields[0]->value;
$field2 = $fields[1]->value;
}

Session expiring for twitter oAuth

I am using Abraham Williams' oAuth library to update a status. The application does not have a UI (other than the prompt from Twitter for credentials. Instead, the user enters a URL in the browser.
When the URL is called, I get an error: "Could not post Tweet. Error: Reason: 1".
I inserted some test code, and it seems as if the session is getting lost in between transitions: $_SESSION['tweetmsg'] is set on initial call in index.php, but then when the switch to connect.php happens, it seems as if the session is lost. Any ideas?
Following is the source code:
index.php
<?php
include_once '../../winsinclude/tw_config.php';
require_once "../../winsinclude/twitteroauth.php";
require_once "../../winsinclude/OAuth.php";
session_start();
if (empty($_SESSION['access_token'])) {
$_SESSION['tweetmsg'] = create_tweet_text();
print "<script>self.location='./connect.php');</script>";
}
$connection = new TwitterOAuth(
CONSUMER_KEY,
CONSUMER_SECRET,
$_SESSION['access_token']['oauth_token'],
$_SESSION['access_token']['oauth_token_secret']
);
if (!isset($_SESSION['tweetmsg'])) {
exit('No tweet value in session or from form');
}
$tweetmsg = $_SESSION['tweetmsg'];
$result = $connection->post('statuses/update', array('status' => $tweetmsg));
unset($_SESSION['tweetmsg']);
if (200 === $connection->http_code) {
echo 'Tweet Posted: '.$tweetmsg;
}
else {
echo 'Could not post Tweet. Error: '.$httpCode.' Reason: '.
session_destroy();
}
function create_tweet_text () {
return 'this is a test';
}
connect.php
?php
session_start();
include_once '../../winsinclude/tw_config.php';
require_once "../../winsinclude/twitteroauth.php";
require_once "../../winsinclude/OAuth.php";
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->getRequestToken(OAUTH_CALLBACK.'callback.php');
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
$url = $connection->getAuthorizeURL($request_token);
print "<script>self.location='$url';</script>";
callback.php
<?php
session_start();
include_once '../../winsinclude/tw_config.php';
require_once "../../winsinclude/twitteroauth.php";
require_once "../../winsinclude/OAuth.php";
if (
isset($_REQUEST['oauth_token'])
&& $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']
) {
echo 'Session expired';
}
else {
$connection = new TwitterOAuth(
CONSUMER_KEY,
CONSUMER_SECRET,
$_SESSION['oauth_token'],
$_SESSION['oauth_token_secret']
);
$_SESSION['access_token'] = $connection->getAccessToken($_REQUEST['oauth_verifier']);
print "<script>self.location='index.php';</script>";
}
Recently Twitter deactivated a number of http urls for oAuth and replaced them with https equivalents. If you can see the URL string http://twitter.com/oauth/request_token in the includes then it means you need to follow https://dev.twitter.com/discussions/10803 and change all the calls to https...

Resources