我尝试在创建新帖子时向Twitter发送通知,但我收到了:
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTProtectedRange;
import java.util.Arrays;
public class CreateExcelXSSFProtectedSheetAllowFilteringAndSorting {
public static void main(String[] args) throws Exception {
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet();
Row row;
Cell cell;
row = sheet.createRow(0);
for (int c = 0 ; c < 4; c++) {
cell = row.createCell(c);
cell.setCellValue("Field " + (c+1));
}
for (int r = 1; r < 10; r++) {
row = sheet.createRow(r);
for (int c = 0 ; c < 4; c++) {
cell = row.createCell(c);
cell.setCellValue("Data R" + (r+1) + "C" + (c+1));
}
}
sheet.setAutoFilter(CellRangeAddress.valueOf("A1:D10"));
((XSSFSheet)sheet).lockAutoFilter(false);
CTProtectedRange protectedRange = ((XSSFSheet)sheet).getCTWorksheet()
.addNewProtectedRanges()
.addNewProtectedRange();
protectedRange.setName("enableSorting");
protectedRange.setSqref(Arrays.asList(new String[]{"A1:D10"}));
((XSSFSheet)sheet).lockSort(false);
sheet.protectSheet("");
for (int c = 0 ; c < 4; c++) {
sheet.autoSizeColumn(c);
}
workbook.write(new FileOutputStream("CreateExcelXSSFProtectedSheetAllowFilteringAndSorting.xlsx"));
workbook.close();
}
}
通知类
Couldn't post Notification. Response: Bad Authentication data.
发布控制器
use NotificationChannels\Twitter\TwitterChannel;
use NotificationChannels\Twitter\TwitterStatusUpdate;
use App\Post;
class PostPublished extends Notification
{
use Queueable;
public function via($notifiable)
{
return [TwitterChannel::class, TelegramChannel::class];
}
public function toTwitter($post)
{
$title = $post->title;
$slug = $post->slug;
$image = $post->image;
return new TwitterStatusUpdate($title .' https://domain.co/blog/'. $slug, [$image]);
}
发布模型
use Illuminate\Notifications\Notifiable;
use App\Notifications\PostPublished;
$post->save();
$post->notify(new \App\Notifications\PostPublished($post));
答案 0 :(得分:1)
您的配置或令牌肯定有问题。它看起来好像没有正确设置某些东西。在config/services.php
文件中,您有以下内容吗?
'twitter' => [
'consumer_key' => env('TWITTER_CONSUMER_KEY'),
'consumer_secret' => env('TWITTER_CONSUMER_SECRET'),
'access_token' => env('TWITTER_ACCESS_TOKEN'),
'access_secret' => env('TWITTER_ACCESS_SECRET')
]
请检查以确保使用修补器正确设置所有这些。在终端类型php artisan tinker
中,然后一次检查以下一行:
env('TWITTER_CONSUMER_KEY'),
env('TWITTER_CONSUMER_SECRET'),
env('TWITTER_ACCESS_TOKEN'),
env('TWITTER_ACCESS_SECRET')
答案 1 :(得分:0)
我需要做的就是:
php artisan config:cach
composer dump-autoload
现在它的工作就像魅力一样。
答案 2 :(得分:0)
请注意,.env文件的任何部分都可能是类型错误,不仅是Twitter访问令牌和密钥,例如:
APP_NAME=Name of your App
代替:
APP_NAME="Name of your App"