Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page token missing #27

Closed
shanwazfarooqe opened this issue Sep 4, 2018 · 13 comments
Closed

Page token missing #27

shanwazfarooqe opened this issue Sep 4, 2018 · 13 comments

Comments

@shanwazfarooqe
Copy link

Page token is missing when using limit data.

LaravelGmail::message()->limit(10)->in( $box = 'inbox' )->preload()->all();

How can i access pagetoken.

@dacastro4
Copy link
Owner

@shanwazfarooqe you know what? Looking at the code I think I totally forgot about that. I'm making a PR right now. Sorry!!!

@dacastro4
Copy link
Owner

@shanwazfarooqe it should be something like:

$messages = LaravelGmail::message();
$messages->take(3)->all(); //gets first 3
$messages->next(); //get next 3

You can access the token via $messages->pageToken

@dacastro4
Copy link
Owner

@shanwazfarooqe please check PR #28

@shanwazfarooqe
Copy link
Author

I am getting error when using take() method.

Call to undefined method Dacastro4\LaravelGmail\Services\Message::take()

@dacastro4
Copy link
Owner

Hey, @shanwazfarooqe can you send me the code that you're using?

@shanwazfarooqe
Copy link
Author

shanwazfarooqe commented Sep 17, 2018 via email

@shanwazfarooqe
Copy link
Author

`<?php

namespace App\Http\Controllers;

use Dacastro4\LaravelGmail\Facade\LaravelGmail;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Validator;

class GmailController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/

protected $access_token;
protected $url;

public function __construct()
{
    $this->middleware('auth');
    if(!LaravelGmail::check())
    {
        return redirect('/oauth/gmail');
    }

    $this->access_token = LaravelGmail::getToken()['access_token'];
    $this->url = "https://www.googleapis.com/gmail/v1/users/me/";
}

public function index($pageToken=null)
{
    if(!LaravelGmail::check())
    {
        return redirect('/oauth/gmail');
    }

    $gmailall = LaravelGmail::message()->in( $box = 'inbox' )->all();
    $inbox = count($gmailall);

    $message_url = $this->url."messages?maxResults=10&q=in:inbox&access_token=".$this->access_token."&pageToken=".$pageToken;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $message_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $gmails = json_decode(curl_exec($ch), true);
    $token = $this->access_token;

    return view('email-api',compact('gmails','token','pageToken','inbox'));
}

public function trash($id=null)
{
    $posts =array('id'=>$id);

    $message_url = $this->url."messages/".$id."/trash?access_token=".$this->access_token;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $message_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, $posts ? 0 :1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($posts));
    $response = json_decode(curl_exec($ch), true);
    if($response){
        return redirect()->route('gmail')->with('status','Email has been deleted');
    } else {
        return redirect()->route('gmail')->with('status','Email could not deleted');
    }
}

public function delete($id=null)
{
    $posts =array('id'=>$id);

    $message_url = $this->url."messages/".$id."?access_token=".$this->access_token;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $message_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    $response = json_decode(curl_exec($ch), true);
    //dd($response);
    if($response){
        return redirect()->route('gmail')->with('status','Email has been deleted');
    } else {
        return redirect()->route('gmail')->with('status','Email could not deleted');
    }
}

public function deleteAll(Request $request)
{
    $ids = $request->ids;

    $queryParams = array(
      'ids' => json_decode($ids)
    );

    $posts = json_encode($queryParams);

    //dd($posts);

    $message_url = $this->url."messages/batchDelete?access_token=".$this->access_token;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $message_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, $posts ? 0 :1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$posts);
    $response = json_decode(curl_exec($ch), true);
    //dd($response);
    if($response){
        return redirect()->route('gmail')->with('status','Email has been deleted');
    } else {
        return redirect()->route('gmail')->with('status','Email could not deleted');
    }
}

public function trashAll(Request $request)
{
    $ids = json_decode($request->ids);
    $response = array();

    foreach($ids as $id):
    $posts =array('id'=>$id);
    $message_url = $this->url."messages/".$id."/trash?access_token=".$this->access_token;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $message_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, $posts ? 0 :1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($posts));
    $response[] = json_decode(curl_exec($ch), true);
    endforeach;

    if($response){
        return redirect()->route('gmail')->with('status','Email has been deleted');
    } else {
        return redirect()->route('gmail')->with('status','Email could not deleted');
    }
}

public function detail($id=null)
{
    $filtered = LaravelGmail::message()->get($id);
    //dd($filtered);
    return view('email-api-detail',compact('filtered'));
}

public function create(Request $request)
{
    $mail = LaravelGmail::message()->to($request->to)->from(LaravelGmail::user())->subject($request->subject)->message($request->content)->send();
    if($mail)
    {
        return redirect()->route('gmail')->with('status','Email has been sent');
    }
    
}

}
`

@dacastro4
Copy link
Owner

@shanwazfarooqe you told me that you had an error with take(), I don't see the take method implemented in here.

@shanwazfarooqe
Copy link
Author

take() method works but i still couldnt get page token. So i used it directly to get pageToken().

@dacastro4
Copy link
Owner

@shanwazfarooqe it should be something like:

$messages = LaravelGmail::message();
$messages->take(3)->all(); //gets first 3
$messages->next(); //get next 3

You can access the token via $messages->pageToken

@shanwazfarooqe did you already try what I said in this message?

@shanwazfarooqe
Copy link
Author

shanwazfarooqe commented Oct 15, 2018 via email

@dacastro4
Copy link
Owner

I'm really sorry @shanwazfarooqe, I've been busy. Did you figure it out? if you haven't, let me know so I can keep the issue open and help you.

@bhavdip111
Copy link

bhavdip111 commented Feb 8, 2019

pageToken

Awesome!
Just have to add pageToken into message collection instance from Message Services.

$messages['pageToken'] = $this->pageToken;

I tried and it's working fine.

So, @dacastro4 can you please update in package.

capture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants